Request for a more powerful template specialization feature

Enamex via Digitalmars-d digitalmars-d at puremagic.com
Sat Jul 15 03:34:13 PDT 2017


On Friday, 14 July 2017 at 19:49:05 UTC, Andrei Alexandrescu 
wrote:
> On 7/14/17 2:19 PM, data pulverizer wrote:
>> template Construct(R: Union{double, int}, W: Union{string, 
>> char, dchar})
>
> template Construct(R, W)
> if ((is(R == double) || is(R == int))
>     && (is(W == string) || is(W == char) || is(W == dchar))
>
>> It would be good to get comments and suggestions before I 
>> write a DIP.
>
> An effective way of improving the state of affairs would be to 
> create a PR that makes the constraint easier to read and write, 
> e.g.:
>
> among!(R, double, int) && among!(W, string, char, dchar)
>
> In fact it's surprising it hasn't been proposed yet.
>
> Andrei

But specializations are quite different from constraints, no? 
Constraints wouldn't help when the template name is overloaded 
and passes the constraint checks of several different template 
implementations; specializations narrow things down for overload 
resolution.

Unless I'm misunderstanding the OP or everyone else in the thread 
somehow :/


More information about the Digitalmars-d mailing list