Template constraints: opCmp and opUnary!"++"

Francesco Cattoglio francesco.cattoglio at gmail.com
Fri Dec 20 09:31:33 PST 2013


On Friday, 20 December 2013 at 16:40:23 UTC, monarch_dodra wrote:
>> Everything works as it should, but according to "D Templates: 
>> A Tutorial" book, you should not use arguments in constraints.
>
> That's news to me.
It seems strange to me too, but: page 69 on the PDF:
"Do not use argument in your constraint. If you need a value of 
type T, use T.init."
Since I don't know D really well, I thought something was wrong 
with it.
> That's normal, because "T.init" is not an lvalue.
Right! I was suspecting something like this.

> That said:
> Seems perfectly legit to me.
Then I'll probably stick to it. It's simple, easy to understand, 
and works.
Or maybe the __traits(compiles) actually looks even better.

> "B" is a type, so "++B" will always resolve to "__error", unless
> you've implemented a static operator (not sure if even legal?).
Best part is: ++B actually works, it's the B < E that fails. But 
they both smelled bad.
Perhaps ++B is some kind of accept-invalid bug then?


More information about the Digitalmars-d-learn mailing list