Skip to content

Commit

Permalink
UFCS for moveAt, moveFront, moveBack
Browse files Browse the repository at this point in the history
  • Loading branch information
9il committed Apr 9, 2016
1 parent ef26d53 commit ddf8268
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 45 deletions.
4 changes: 2 additions & 2 deletions std/algorithm/mutation.d
Expand Up @@ -2407,8 +2407,8 @@ void swapAt(R)(auto ref R r, size_t i1, size_t i2)
else
{
if (i1 == i2) return;
auto t1 = moveAt(r, i1);
auto t2 = moveAt(r, i2);
auto t1 = r.moveAt(i1);
auto t2 = r.moveAt(i2);
r[i2] = t1;
r[i1] = t2;
}
Expand Down
10 changes: 5 additions & 5 deletions std/algorithm/sorting.d
Expand Up @@ -414,7 +414,7 @@ Range partition(alias predicate,
}
else
{
auto t1 = moveFront(r), t2 = moveBack(r);
auto t1 = r.moveFront(), t2 = r.moveBack();
r.front = t2;
r.back = t1;
}
Expand Down Expand Up @@ -1530,11 +1530,11 @@ private template TimSortImpl(alias pred, R)
}
body
{
import std.algorithm : move; // FIXME
import std.algorithm.mutation : move;

for (; sortedLen < range.length; ++sortedLen)
{
T item = moveAt(range, sortedLen);
T item = range.moveAt(sortedLen);
size_t lower = 0;
size_t upper = sortedLen;
while (upper != lower)
Expand All @@ -1548,8 +1548,8 @@ private template TimSortImpl(alias pred, R)
//11 instructions vs 7 in the innermost loop [checked on Win32]
//moveAll(retro(range[lower .. sortedLen]),
// retro(range[lower+1 .. sortedLen+1]));
for(upper=sortedLen; upper>lower; upper--)
range[upper] = moveAt(range, upper-1);
for(upper=sortedLen; upper > lower; upper--)
range[upper] = range.moveAt(upper - 1);
range[lower] = move(item);
}
}
Expand Down
8 changes: 4 additions & 4 deletions std/container/binaryheap.d
Expand Up @@ -115,8 +115,8 @@ if (isRandomAccessRange!(Store) || isRandomAccessRange!(typeof(Store.init[])))
{
assert(!store.empty, "Cannot pop an empty store.");
if (store.length == 1) return;
auto t1 = moveFront(store[]);
auto t2 = moveBack(store[]);
auto t1 = store[].moveFront();
auto t2 = store[].moveBack();
store.front = move(t2);
store.back = move(t1);
percolate(store[], 0, store.length - 1);
Expand Down Expand Up @@ -293,8 +293,8 @@ Removes the largest element from the heap.
enforce(!empty, "Cannot call removeFront on an empty heap.");
if (_length > 1)
{
auto t1 = moveFront(_store[]);
auto t2 = moveAt(_store[], _length - 1);
auto t1 = _store[].moveFront();
auto t2 = _store[].moveAt(_length - 1);
_store.front = move(t2);
_store[_length - 1] = move(t1);
}
Expand Down
6 changes: 3 additions & 3 deletions std/range/interfaces.d
Expand Up @@ -332,7 +332,7 @@ template InputRangeObject(R) if (isInputRange!(Unqual!R)) {
@property E front() { return _range.front; }

E moveFront() {
return .moveFront(_range);
return _range.moveFront();
}

void popFront() { _range.popFront(); }
Expand All @@ -354,7 +354,7 @@ template InputRangeObject(R) if (isInputRange!(Unqual!R)) {
@property E back() { return _range.back; }

E moveBack() {
return .moveBack(_range);
return _range.moveBack();
}

void popBack() { return _range.popBack(); }
Expand All @@ -372,7 +372,7 @@ template InputRangeObject(R) if (isInputRange!(Unqual!R)) {
}

E moveAt(size_t index) {
return .moveAt(_range, index);
return _range.moveAt(index);
}

static if (hasAssignableElements!R) {
Expand Down
62 changes: 31 additions & 31 deletions std/range/package.d
Expand Up @@ -243,19 +243,19 @@ if (isBidirectionalRange!(Unqual!Range))
@property auto ref back() { return source.front; }
void popBack() { source.popFront(); }

static if(is(typeof(.moveBack(source))))
static if(is(typeof(source.moveBack())))
{
ElementType!R moveFront()
{
return .moveBack(source);
return source.moveBack();
}
}

static if(is(typeof(.moveFront(source))))
static if(is(typeof(source.moveFront())))
{
ElementType!R moveBack()
{
return .moveFront(source);
return source.moveFront();
}
}

Expand Down Expand Up @@ -284,11 +284,11 @@ if (isBidirectionalRange!(Unqual!Range))
}
}

static if (is(typeof(.moveAt(source, 0))))
static if (is(typeof(source.moveAt(0))))
{
ElementType!R moveAt(IndexType index)
{
return .moveAt(source, retroIndex(index));
return source.moveAt(retroIndex(index));
}
}

Expand Down Expand Up @@ -516,7 +516,7 @@ body
{
ElementType!R moveFront()
{
return .moveFront(source);
return source.moveFront();
}
}

Expand Down Expand Up @@ -572,7 +572,7 @@ body
ElementType!R moveBack()
{
eliminateSlackElements();
return .moveBack(source);
return source.moveBack();
}
}

Expand All @@ -596,11 +596,11 @@ body
/**
Forwards to $(D moveAt(source, n)).
*/
static if (is(typeof(.moveAt(source, 0))))
static if (is(typeof(source.moveAt(0))))
{
ElementType!R moveAt(size_t n)
{
return .moveAt(source, _n * n);
return source.moveAt(_n * n);
}
}

Expand Down Expand Up @@ -947,7 +947,7 @@ if (Ranges.length > 0 &&
foreach (i, Unused; R)
{
if (source[i].empty) continue;
return .moveFront(source[i]);
return source[i].moveFront();
}
assert(false);
}
Expand Down Expand Up @@ -982,7 +982,7 @@ if (Ranges.length > 0 &&
foreach_reverse (i, Unused; R)
{
if (source[i].empty) continue;
return .moveBack(source[i]);
return source[i].moveBack();
}
assert(false);
}
Expand Down Expand Up @@ -1046,12 +1046,12 @@ if (Ranges.length > 0 &&
{
static if (isInfinite!(Range))
{
return .moveAt(source[i], index);
return source[i].moveAt(index);
}
else
{
immutable length = source[i].length;
if (index < length) return .moveAt(source[i], index);
if (index < length) return source[i].moveAt(index);
index -= length;
}
}
Expand Down Expand Up @@ -1830,7 +1830,7 @@ if (isInputRange!(Unqual!Range) &&
assert(!empty,
"Attempting to move the front of an empty "
~ Take.stringof);
return .moveFront(source);
return source.moveFront();
}
}

Expand Down Expand Up @@ -1918,15 +1918,15 @@ if (isInputRange!(Unqual!Range) &&
assert(!empty,
"Attempting to move the back of an empty "
~ Take.stringof);
return .moveAt(source, this.length - 1);
return source.moveAt(this.length - 1);
}

auto moveAt(size_t index)
{
assert(index < length,
"Attempting to index out of the bounds of a "
~ Take.stringof);
return .moveAt(source, index);
return source.moveAt(index);
}
}
}
Expand Down Expand Up @@ -2175,7 +2175,7 @@ if (isInputRange!R)
assert(!empty,
"Attempting to move the front of an empty "
~ typeof(this).stringof);
return .moveFront(_input);
return _input.moveFront();
}
}

Expand Down Expand Up @@ -3655,7 +3655,7 @@ struct Zip(Ranges...)
{
ElementType moveFront()
{
@property tryMoveFront(size_t i)(){return ranges[i].empty ? tryGetInit!i() : .moveFront(ranges[i]);}
@property tryMoveFront(size_t i)(){return ranges[i].empty ? tryGetInit!i() : ranges[i].moveFront();}
//ElementType(tryMoveFront!0, tryMoveFront!1, ...)
return mixin(q{ElementType(%(tryMoveFront!%s, %))}.format(iota(0, R.length)));
}
Expand Down Expand Up @@ -3684,7 +3684,7 @@ struct Zip(Ranges...)
{
//TODO: Fixme! BackElement != back of all ranges in case of jagged-ness

@property tryMoveBack(size_t i)(){return ranges[i].empty ? tryGetInit!i() : .moveFront(ranges[i]);}
@property tryMoveBack(size_t i)(){return ranges[i].empty ? tryGetInit!i() : ranges[i].moveFront();}
//ElementType(tryMoveBack!0, tryMoveBack!1, ...)
return mixin(q{ElementType(%(tryMoveBack!%s, %))}.format(iota(0, R.length)));
}
Expand Down Expand Up @@ -3865,8 +3865,8 @@ struct Zip(Ranges...)
//TODO: Fixme! This may create an out of bounds access
//for StoppingPolicy.longest

//ElementType(.moveAt(ranges[0], n), .moveAt(ranges[1], n), ..., )
return mixin (q{ElementType(%(.moveAt(ranges[%s], n)%|, %))}.format(iota(0, R.length)));
//ElementType(ranges[0].moveAt(n), ranges[1].moveAt(n), ..., )
return mixin (q{ElementType(%(ranges[%s].moveAt(n)%|, %))}.format(iota(0, R.length)));
}
}
}
Expand Down Expand Up @@ -5388,7 +5388,7 @@ struct FrontTransversal(Ror,
{
ElementType moveFront()
{
return .moveFront(_input.front);
return _input.front.moveFront();
}
}

Expand Down Expand Up @@ -5445,7 +5445,7 @@ struct FrontTransversal(Ror,
{
ElementType moveBack()
{
return .moveFront(_input.back);
return _input.back.moveFront();
}
}

Expand Down Expand Up @@ -5478,7 +5478,7 @@ struct FrontTransversal(Ror,
{
ElementType moveAt(size_t n)
{
return .moveFront(_input[n]);
return _input[n].moveFront();
}
}
/// Ditto
Expand Down Expand Up @@ -5670,7 +5670,7 @@ struct Transversal(Ror,
{
E moveFront()
{
return .moveAt(_input.front, _n);
return _input.front.moveAt(_n);
}
}

Expand Down Expand Up @@ -5727,7 +5727,7 @@ struct Transversal(Ror,
{
E moveBack()
{
return .moveAt(_input.back, _n);
return _input.back.moveAt(_n);
}
}

Expand Down Expand Up @@ -5762,7 +5762,7 @@ struct Transversal(Ror,
{
E moveAt(size_t n)
{
return .moveAt(_input[n], _n);
return _input[n].moveAt(_n);
}
}

Expand Down Expand Up @@ -6098,7 +6098,7 @@ struct Indexed(Source, Indices)
auto moveFront()
{
assert(!empty);
return .moveAt(_source, _indices.front);
return _source.moveAt(_indices.front);
}
}

Expand Down Expand Up @@ -6135,7 +6135,7 @@ struct Indexed(Source, Indices)
auto moveBack()
{
assert(!empty);
return .moveAt(_source, _indices.back);
return _source.moveAt(_indices.back);
}
}
}
Expand Down Expand Up @@ -6181,7 +6181,7 @@ struct Indexed(Source, Indices)
/// Ditto
auto moveAt(size_t index)
{
return .moveAt(_source, _indices[index]);
return _source.moveAt(_indices[index]);
}
}
}
Expand Down

0 comments on commit ddf8268

Please sign in to comment.