Template functions, can we make it more simple?
SteveGuo
steveguo at outlook.com
Fri Aug 2 14:20:54 PDT 2013
>
> I think it could get pretty confusing. I.e.:
>
> module foo;
>
> struct a { }
> struct b { }
>
> ----
> module bar;
>
> import foo;
>
> auto Add(a, b) { } // [1]
>
> ----
> [1] Here the unsuspecting programmer thinks he's writing a
> template function, not knowing that one module he's importing
> actually specifies 'a' and 'b' as types, which makes his Add a
> regular function taking unnamed variables of types 'a' and 'b'.
We know that normal function parameter declaration is the form of
"PARAMTYPE param"
but in this declaration "auto Add(a, b) { }" the parameter do not
have PARAMTYPE, compiler can detect this issue, so, the compiler
knows a or b is not a type, it treats them as template
More information about the Digitalmars-d
mailing list