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

so so at so.do
Tue Dec 14 10:51:50 PST 2010


> Any idea how this can be 'solved' or do we need to continue doing things  
> like this?  My naive instinct is to use the declaration order to  
> determine a match (first one to match wins), but that kind of goes  
> against other overloads in D.

One big plus of current solution is that everything you need for that  
specialization lies in the signature.
I can't see another approach that scales better at this. If scaling for  
constraints is something important.

In:
void foo(R)(R r) if(isRandomAccessRange!R) {...}
void foo(R)(R r) if(isInputRange!R && !isRandomAccessRange!R) {...}

void foo(R)(R r) if(isInputRange!R && !isRandomAccessRange!R) {...}
We can deduce it is equal to:
void foo(R)(R r) if(isInputRange!R) {...}

For single/two constraints it isn't hard, when things get ugly determining  
what means what is not quite easy as far as i can see.
Just consider if your first specialization had two constraints.

-- 
Using Opera's revolutionary email client: http://www.opera.com/mail/


More information about the Digitalmars-d mailing list