Skip to content

Commit

Permalink
Fix Cycle!(T[N]).opSlice return type qualifier.
Browse files Browse the repository at this point in the history
This is a fixup for commit 3faffc3.
  • Loading branch information
dnadlinger committed Jan 13, 2014
1 parent 9cb7cab commit 4c0c732
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions std/range.d
Expand Up @@ -4463,7 +4463,7 @@ nothrow:
return this[i .. $].takeExactly(j - i);
}

typeof(this) opSlice(size_t i, DollarToken) inout
inout(typeof(this)) opSlice(size_t i, DollarToken) inout
{
return Cycle(*cast(R*)_ptr, _index + i);
}
Expand Down Expand Up @@ -4500,13 +4500,6 @@ unittest
assert(equal(take(cycle([1, 2][]), 5), [ 1, 2, 1, 2, 1 ][]));
static assert(isForwardRange!(Cycle!(uint[])));

int[3] a = [ 1, 2, 3 ];
static assert(isStaticArray!(typeof(a)));
auto c = cycle(a);
assert(a.ptr == c._ptr);
assert(equal(take(cycle(a), 5), [ 1, 2, 3, 1, 2 ][]));
static assert(isForwardRange!(typeof(c)));

// Make sure ref is getting propagated properly.
int[] nums = [1,2,3];
auto c2 = cycle(nums);
Expand Down Expand Up @@ -4566,6 +4559,22 @@ unittest
}
}

unittest // For static arrays.
{
int[3] a = [ 1, 2, 3 ];
static assert(isStaticArray!(typeof(a)));
auto c = cycle(a);
assert(a.ptr == c._ptr);
assert(equal(take(cycle(a), 5), [ 1, 2, 3, 1, 2 ][]));
static assert(isForwardRange!(typeof(c)));

// Test qualifiers on slicing.
alias C = typeof(c);
static assert(is(typeof(c[1 .. $]) == C));
const cConst = c;
static assert(is(typeof(cConst[1 .. $]) == const(C)));
}

unittest // For infinite ranges
{
struct InfRange
Expand Down

0 comments on commit 4c0c732

Please sign in to comment.