implicit template constraint notation

bearophile bearophileHUGS at lycos.com
Mon Jun 10 02:19:55 PDT 2013


Timothee Cour:

> A)
> I'd like to simplify notation of template function declarations 
> involving
> only single-argument boolean template constraints as follows:
>
> example:
> A1: 'auto myfunction ( isSomeString a, isInputRange b) {...}'
>
> would be rewritten by compiler as:
> A2: 'auto myfunction(T0,T1) (T0 a, T1 b) if(isSomeString!T1 a &&
> isInputRange!T b) {...}'
>
> IMO, A1 is less verbose and clearer than A2.
>
> Obviously, more complex template constraints would still 
> require the full
> syntax, but I'd argue this case is the most common.

See:
http://forum.dlang.org/thread/xaganckgcdkfcmjamogh@forum.dlang.org


> B)
> Secondly, ddoc doesn't generate template constraints or does so 
> very
> inconsistently :
> in http://dlang.org/phobos/std_algorithm.html we have:
> template map(fun...) if (fun.length >= 1);
> but all other template constraints are omitted, eg:
> void fill(Range, Value)(Range range, Value filler); // template 
> constraint
> omitted.
> Using the notation proposed in A, wherever applicable, would 
> make documentation clear.

That sounds like a bug report for bugzilla.

Bye,
bearophile


More information about the Digitalmars-d mailing list