So how exactly does one make a persistent range object?

Jonathan M Davis jmdavisProg at gmx.com
Sat Jun 4 22:34:52 PDT 2011


On 2011-06-04 18:01, Andrej Mitrovic wrote:
> Problem not so much solved.
> 
> What if I want to keep a stride range? There's no Stride struct
> defined in std.range, stride() is defined as an auto function and
> hides the type inside the function itself.
> 
> How I can store such an object in module scope? This won't work:
> 
> auto var = stride([1, 2, 3], 2);
> 
> This prints out a couple of hundred lines of text as an error message
> followed by "not implemented yet in CTFE".

The problem here is likely because var _must_ be known at compile time when 
you initialize it directly, and stride apparently doesn't work with CTFE. I 
believe that it's the case that _most_ range-based functions don't work with 
CTFE yet. So, you'll need to initialize it in a module constructor. So, to get 
the type, you'll probably need to do something like

typeof(stride([1, 2, 3], 2)) var;

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list