Request for a more powerful template specialization feature

data pulverizer via Digitalmars-d digitalmars-d at puremagic.com
Fri Jul 14 15:49:18 PDT 2017


On Friday, 14 July 2017 at 22:25:15 UTC, data pulverizer wrote:
> I am aware that this suggestion touches the language and the 
> compiler - and may significant implications. I would like to 
> know whether this could be done without too much effort and 
> whether it would break anything else?
>
> If you are writing lots of overloaded templates, constraints 
> can have unintended behaviour because you end up telling the 
> compiler what not to do rather than what to do. The above 
> Unions are clear and simple, easy to use and should result in 
> cleaner more robust code.

In addition with template specializations you get constraints for 
free. If I implement template overloads which are all 
specializations, the compiler gives me a very informative error 
if I step outside the pre-defined set of implementations. That's 
just brilliant - exactly what you want! I immediately know when I 
see that error what the issue is. Am I being naive? Why are 
constraints better?


More information about the Digitalmars-d mailing list