Reducing template constraint verbosity? [was Re: Slides from my ACCU Silicon Valley talk]

Steven Schveighoffer schveiguy at yahoo.com
Tue Dec 14 13:40:51 PST 2010


On Tue, 14 Dec 2010 16:35:49 -0500, Andrei Alexandrescu  
<SeeWebsiteForEmail at erdani.org> wrote:

> On 12/14/10 2:44 PM, Steven Schveighoffer wrote:
>> On Tue, 14 Dec 2010 15:35:30 -0500, Patrick Down <pat at codemoon.com>  
>> wrote:
>>
>>> == Quote from Steven Schveighoffer (schveiguy at yahoo.com)'s article
>>> Would it help to allow 'else' and 'else if' on the template  
>>> constraints?
>>>
>>> void foo(R)(R r) if(isRandomAccessRange!R)
>>> {...}
>>> else if(isInputRange!R)
>>> {...}
>>>
>>> This could basically be translated into two specializations like this:
>>>
>>> void foo(R)(R r) if(isRandomAccessRange!R) {...}
>>> void foo(R)(R r) if(isInputRange!R && !isRandomAccessRange!R) {...}
>>
>> :O
>>
>> Wow, that's a great idea.
>>
>> Andrei?
>
> I'll cautiously say "looks okay", but in terms of allowing us to do  
> great things, it is way below many other things.
>
> Consider for example the annoying limitation with the eponymous trick:  
> you can't define any other symbols. That is unnecessary and causes a lot  
> of code and name bloat. I'd much prefer that issue were fixed instead of  
> the above.

I agree.  My original question was just "have we thought about this", not  
"this must be solved immediately!"

If this was implemented, it would be backwards-compatible anyways, so it's  
not pressing.

-Steve


More information about the Digitalmars-d mailing list