Producing nicer template errors in D libraries

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Wed Apr 11 07:33:26 PDT 2012


On 4/11/12 9:23 AM, Steven Schveighoffer wrote:
> Essentially, you are still forcing this sequence:
>
> int func(T)(T arg) if(constraint) {...}
> int func(T)(T arg) if(!constraint) {...}
>
> when the second line could just be:
>
> int func(T)(T arg) else {...}
>
> I don't see the benefit of enforcing the else branch to give an error.

I advocated this to Walter and he talked me out of it.

Essentially template constraints help choosing the right overload given 
the arguments. Just like overloading, such selection should proceed 
across modules. If we have an "else" template we give up on that 
approach. Besides, it's extremely rare that a template works with an 
open-bounded set of types.

Andrei




More information about the Digitalmars-d mailing list