Fun with templates

Jacob Carlborg doob at me.com
Mon Jul 8 00:34:16 PDT 2013


On 2013-07-08 04:10, Manu wrote:

> Hmmm, this is an interesting point.
> I initially thought this was desirable, it could be useful.
> But now that you point it out, I guess the point you are making is that
> they will all mangle separately anyway?
> That seems problematic, because since all have the same return value and
> physical arguments, how does the compiler choose an overload to call in
> various circumstances?
> I think I (mistakenly?) presumed they would all mangle the same, since
> they have the same physical signature (return value + physical args),
> and therefore all be the same function (eliminating the duplicates).

Template arguments are part of the mangled name. Example:

int foo (string a) (int b)
{
     return b;
}

int bar (int b)
{
     return b;
}

assert(foo!("a").mangleof == "_D4main17__T3fooVAyaa1_61Z3fooFNaNbNfiZi");
assert(foo!("abcdefg").mangleof == 
"_D4main29__T3fooVAyaa7_61626364656667Z3fooFNaNbNfiZi");
assert(bar.mangleof == "_D4main3barFiZi");

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list