implicit template constraint notation

Timothee Cour thelastmammoth at gmail.com
Sun Jun 9 20:51:09 PDT 2013


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.


More generally, the compiler would rewrite:
'auto myfunction(Tj...) (modifier_i Ei ai,...) if(condition(Tj) ) {...}'
as:
'auto myfunction(Tj...,T'k...) (modifier_i E'i ai,...) if(condition(Tj) &&
Ek!T'k &...) {...}'
where, for each i, if Ei is the name (in current scope) of a template that
has a single argument and that returns a boolean, then introduce E'i as
type T'i, else E'i=Ei; and k ranges over the list of indexes i that
represent the former case.


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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20130609/3a3be984/attachment.html>


More information about the Digitalmars-d mailing list