On Sunday, 23 September 2012 at 21:52:23 UTC, Timon Gehr wrote:
On 09/23/2012 10:57 PM, Ali Çehreli wrote:
...

Also, I think your code should have passed a range like R.init to
takeExactly, not R, which is a type:

  takeExactly(R.init, 1)

I don't know why your code compiles.


See discussion here:
http://d.puremagic.com/issues/show_bug.cgi?id=8220

Interesting. Thanks.

On Sunday, 23 September 2012 at 21:53:20 UTC, Jonathan M Davis wrote:
On Sunday, September 23, 2012 14:47:27 Timon Gehr wrote:
template Hello(R) if(is(typeof(R._input.takeExactly(2)) == R)){
     alias R Hello;
}

Thanks. That does the trick quite cleanly, though you'd think that it would be possible to test whether a template argument is the result of takeExactly without caring or knowing about the guts of takeExactly. So, this isn't a general purpose solution at all, when I think that there should be one. Still, I don't need a general purpose one for what I'm doing, so this should work
just fine.

- Jonathan M Davis

What is wrong with my proposed solution?

----
import std.range;

template Hello(R)
    if ( is(typeof(takeExactly(R.init, 1))) &&
         is(R == typeof(takeExactly(R.init, 1)))
    )
{
    alias R Hello;
}

struct R
{
    enum empty = false;
    @property int front();
    void popFront();
}

struct S{}

void main( ) {
     Hello!(int[]) a; //OK
     Hello!R b;       //Fails second Check: R == typeof(...)
Hello!S c; //Fails first check: is(typeof(takeExactly(...)))
}
----

Forgive me again if there is something wrong with it, but this time, I think it is correct...?

Reply via email to