On Friday, 20 December 2013 at 15:38:56 UTC, Francesco Cattoglio
wrote:
I'm trying to experiment a bit around the iota function.
If I try to impose the following constraits:



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.

If I try doing something like:

auto my_iota(B, E)(B begin, E end)
if (is (typeof(++B.init)) && is (typeof(B.init < E.init))) {}

the code stops compiling for integers.

That's normal, because "T.init" is not an lvalue.

If you need an lvalue, we have `std.traits.lvalueOf!T` which you
can use.

That said:

auto my_iota(B, E)(B begin, E end)
if (is (typeof(++begin)) && is (typeof(begin < end))) {}

Seems perfectly legit to me.

On the other hand the code

auto my_iota(B, E)(B begin, E end)
if (is (typeof(++B)) && is (typeof(B < E))) {}

fails to compile for both integers and my defined types.

"B" is a type, so "++B" will always resolve to "__error", unless
you've implemented a static operator (not sure if even legal?).

Reply via email to