Annoyance with function template unwrapping

Paul Backus snarwin at gmail.com
Sun Jan 17 19:29:59 UTC 2021


On Sunday, 17 January 2021 at 18:36:13 UTC, kdevel wrote:
>
> It's odd behavior. It seems that in D template definitions are 
> things
> in itself (like a struct definition) which obey a one 
> declaration (!) rule.

It's not exactly a one-declaration rule. Templates, like 
functions, can be overloaded:

template foo(T) {
     enum foo = "overload one";
}

template foo(T, U) {
     enum foo = "overload two";
}

static assert(foo!int == "overload one");
static assert(foo!(int, double) == "overload two");

As long as the overloads are unambiguous, there's no problem. As 
with functions, it's only when you have two overloads that match 
the same arguments that you get an error.


More information about the Digitalmars-d mailing list