error when std.range.Cycle of static array is a member
Jonathan M Davis
jmdavisProg at gmx.com
Sun Jul 24 03:19:47 PDT 2011
On Sunday 24 July 2011 12:06:47 Lutger Blijdestijn wrote:
> I'm trying to have a Cycle range of a static array as a struct member, but
> getting a compilation error. Can anybody tell me if I'm doing something
> wrong, or is this a bug?
>
> import std.range;
>
> struct Foo
> {
> ubyte[] buf;
> Cycle!(typeof(buf)) cbuf1; // ok
>
> ubyte[1024] staticBuf;
> Cycle!(typeof(staticBuf)) cbuf2; // error
>
> void test()
> {
> Cycle!(typeof(staticBuf)) cbuf3;
> cbuf3 = cycle(staticBuf); // ok
> }
> }
>
> /std/range.d(228): Error: template instance std.array.front!(ubyte[1024u])
> incompatible arguments for template instantiation
static arrays are not ranges. You can't pop the front off of them, so no range-
based algorithm would work with a static range. Now, you _can_ get a dynamic
range over a static range and _that_ is a valid range, so what you need to do
is make the Cycle a Cycle!(ubyte[]) rather than Cycle!(ubyte[1024]), and you
when you pass the static array to cycle, you need to slice it:
cycle(staticBuf[]).
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list