Skip to content

Commit

Permalink
More isMutable guards
Browse files Browse the repository at this point in the history
  • Loading branch information
nordlow committed Oct 19, 2014
1 parent be6b5f8 commit ce6b9e9
Showing 1 changed file with 43 additions and 26 deletions.
69 changes: 43 additions & 26 deletions std/container/array.d
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ Defines the container's primary range, which is a random-access range.

private this(ref A data, size_t a, size_t b)
{
_outer = data;
_outer_ = data;
_a = a;
_b = b;
}
Expand Down Expand Up @@ -320,24 +320,29 @@ Defines the container's primary range, which is a random-access range.
return _outer[_a + i];
}

Range!(const(A)) opSlice() const
static if (isMutable!T)
{
return typeof(this)(_outer, _a, _b);
}
Range!(A) opSlice()
{
return typeof(this)(_outer, _a, _b);
}

Range!(const(A)) opSlice(size_t i, size_t j) const
{
version (assert) if (i > j || _a + j > _b) throw new RangeError();
return typeof(this)(_outer, _a + i, _a + j);
Range!(A) opSlice()
{
return typeof(return)(_outer, _a, _b);
}
Range!(A) opSlice(size_t i, size_t j)
{
version (assert) if (i > j || _a + j > _b) throw new RangeError();
return typeof(return)(_outer, _a + i, _a + j);
}
}
Range!(A) opSlice(size_t i, size_t j)
else
{
version (assert) if (i > j || _a + j > _b) throw new RangeError();
return typeof(this)(_outer, _a + i, _a + j);
Range!(const(A)) opSlice() const
{
return typeof(return)(_outer, _a, _b);
}
Range!(const(A)) opSlice(size_t i, size_t j) const
{
version (assert) if (i > j || _a + j > _b) throw new RangeError();
return typeof(return)(_outer, _a + i, _a + j);
}
}

void opSliceAssign(T value)
Expand Down Expand Up @@ -462,13 +467,19 @@ forward order.
Complexity: $(BIGOH 1)
*/
Range!(const(Array!T)) opSlice() const
static if (isMutable!T)
{
return typeof(return)(this, 0, length);
Range!(Array!T) opSlice()
{
return typeof(return)(this, 0, length);
}
}
Range!(Array!T) opSlice()
else
{
return typeof(return)(this, 0, length);
Range!(const(Array!T)) opSlice() const
{
return typeof(return)(this, 0, length);
}
}

/**
Expand All @@ -479,15 +490,21 @@ Precondition: $(D a <= b && b <= length)
Complexity: $(BIGOH 1)
*/
Range!(const(Array!T)) opSlice(size_t i, size_t j) const
static if (isMutable!T)
{
version (assert) if (i > j || j > length) throw new RangeError();
return typeof(return)(this, i, j);
Range!(Array!T) opSlice(size_t i, size_t j)
{
version (assert) if (i > j || j > length) throw new RangeError();
return typeof(return)(this, i, j);
}
}
Range!(Array!T) opSlice(size_t i, size_t j)
else
{
version (assert) if (i > j || j > length) throw new RangeError();
return typeof(return)(this, i, j);
Range!(const(Array!T)) opSlice(size_t i, size_t j) const
{
version (assert) if (i > j || j > length) throw new RangeError();
return typeof(return)(this, i, j);
}
}

/**
Expand Down

0 comments on commit ce6b9e9

Please sign in to comment.