implicit template constraint notation

Timothee Cour thelastmammoth at gmail.com
Mon Jun 10 14:35:27 PDT 2013


On Mon, Jun 10, 2013 at 2:19 AM, bearophile <bearophileHUGS at lycos.com>wrote:

> 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<http://forum.dlang.org/thread/xaganckgcdkfcmjamogh@forum.dlang.org>


ah, great! So I guess it must indeed be a good idea!

from the link:
>  If you have two or more types, they must be the same (if you don't want
this, you have to use the normal longer syntax)

In what I suggest, the restriction is much weaker so it'd be more generally
applicable: for example, 'auto myfunction ( isSomeString a, isInputRange
b)' would work in what I suggest but not with the proposal in the link. I
don't think it adds any confusion.

Should I draft a DIP?
I'd like to get more feedback before though.


I'll also reply on the above link (CppNow 2013) for your second proposal
from cppnow (i think variant does already that).



>
>  B)
>> Secondly, ddoc doesn't generate template constraints or does so very
>> inconsistently :
>> in http://dlang.org/phobos/std_**algorithm.html<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.
>

just filed: http://d.puremagic.com/issues/show_bug.cgi?id=10325
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20130610/5507aef6/attachment.html>


More information about the Digitalmars-d mailing list