Structs with a disabled default ctor can't pass as ranges

Steven Schveighoffer schveiguy at yahoo.com
Mon Sep 26 05:31:57 PDT 2011


On Sat, 24 Sep 2011 17:33:37 -0400, Andrej Mitrovic  
<andrej.mitrovich at gmail.com> wrote:

> I've ran into a bit of an issue. isInputRange is defined like this:
>
> template isInputRange(R)
> {
>     enum bool isInputRange = is(typeof(
>     {
>         R r;              // can define a range object
>         if (r.empty) {}   // can test for empty
>         r.popFront();     // can invoke popFront()
>         auto h = r.front; // can get the front of the range
>     }()));
> }
>
> But this will fail for structs which have a disabled default ctor. Was
> this planned?

I don't think this was planned.

I think this should fix it:

R r = R.init;

-Steve


More information about the Digitalmars-d mailing list