mirror of
https://github.com/dlang/phobos.git
synced 2025-05-01 07:30:33 +03:00
use constructors instead of move
This commit is contained in:
parent
5c10e1faf5
commit
b8610beec3
3 changed files with 89 additions and 66 deletions
|
@ -1641,6 +1641,12 @@ if (isInputRange!R)
|
|||
if (!_input.empty) popFront();
|
||||
}
|
||||
|
||||
private this(R input, Tuple!(MutableE, uint) current)
|
||||
{
|
||||
_input = input;
|
||||
_current = current;
|
||||
}
|
||||
|
||||
///
|
||||
void popFront()
|
||||
{
|
||||
|
@ -1686,12 +1692,7 @@ if (isInputRange!R)
|
|||
///
|
||||
@property typeof(this) save()
|
||||
{
|
||||
import std.algorithm.mutation : move;
|
||||
typeof(this) ret = this;
|
||||
auto saved = this._input.save;
|
||||
move(saved, ret._input);
|
||||
ret._current = this._current;
|
||||
return ret;
|
||||
return Group(_input.save, _current);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5161,6 +5162,24 @@ private struct SplitterResult(alias isTerminator, Range)
|
|||
_end = size_t.max;
|
||||
}
|
||||
|
||||
static if (fullSlicing)
|
||||
{
|
||||
private this(Range input, size_t end)
|
||||
{
|
||||
_input = input;
|
||||
_end = end;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
private this(Range input, size_t end, Range next)
|
||||
{
|
||||
_input = input;
|
||||
_end = end;
|
||||
_next = next;
|
||||
}
|
||||
}
|
||||
|
||||
static if (isInfinite!Range)
|
||||
{
|
||||
enum bool empty = false; // Propagate infiniteness.
|
||||
|
@ -5225,16 +5244,10 @@ private struct SplitterResult(alias isTerminator, Range)
|
|||
|
||||
@property typeof(this) save()
|
||||
{
|
||||
import std.algorithm.mutation : move;
|
||||
auto ret = this;
|
||||
auto savedInput = _input.save;
|
||||
move(savedInput, ret._input);
|
||||
static if (!fullSlicing)
|
||||
{
|
||||
auto savedNext = _next.save;
|
||||
move(savedNext, ret._next);
|
||||
}
|
||||
return ret;
|
||||
static if (fullSlicing)
|
||||
return SplitterResult(_input.save, _end);
|
||||
else
|
||||
return SplitterResult(_input.save, _end, _next.save);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4921,6 +4921,7 @@ if (isInputRange!Range)
|
|||
private bool _done;
|
||||
|
||||
static if (!is(Sentinel == void))
|
||||
{
|
||||
///
|
||||
this(Range input, Sentinel sentinel,
|
||||
OpenRight openRight = Yes.openRight)
|
||||
|
@ -4930,7 +4931,17 @@ if (isInputRange!Range)
|
|||
_openRight = openRight;
|
||||
_done = _input.empty || openRight && predSatisfied();
|
||||
}
|
||||
private this(Range input, Sentinel sentinel, OpenRight openRight,
|
||||
bool done)
|
||||
{
|
||||
_input = input;
|
||||
_sentinel = sentinel;
|
||||
_openRight = openRight;
|
||||
_done = done;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
///
|
||||
this(Range input, OpenRight openRight = Yes.openRight)
|
||||
{
|
||||
|
@ -4938,6 +4949,13 @@ if (isInputRange!Range)
|
|||
_openRight = openRight;
|
||||
_done = _input.empty || openRight && predSatisfied();
|
||||
}
|
||||
private this(Range input, OpenRight openRight, bool done)
|
||||
{
|
||||
_input = input;
|
||||
_openRight = openRight;
|
||||
_done = done;
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
@property bool empty()
|
||||
|
@ -4979,30 +4997,13 @@ if (isInputRange!Range)
|
|||
|
||||
static if (isForwardRange!Range)
|
||||
{
|
||||
static if (!is(Sentinel == void))
|
||||
///
|
||||
@property Until save()
|
||||
{
|
||||
import std.algorithm.mutation : move;
|
||||
Until result = this;
|
||||
auto saved = _input.save;
|
||||
move(saved, result._input);
|
||||
result._sentinel = _sentinel;
|
||||
result._openRight = _openRight;
|
||||
result._done = _done;
|
||||
return result;
|
||||
}
|
||||
static if (is(Sentinel == void))
|
||||
return Until(_input.save, _openRight, _done);
|
||||
else
|
||||
///
|
||||
@property Until save()
|
||||
{
|
||||
import std.algorithm.mutation : move;
|
||||
Until result = this;
|
||||
auto saved = _input.save;
|
||||
move(saved, result._input);
|
||||
result._openRight = _openRight;
|
||||
result._done = _done;
|
||||
return result;
|
||||
return Until(_input.save, _sentinel, _openRight, _done);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -972,14 +972,20 @@ if (Ranges.length > 0 &&
|
|||
static if (allSatisfy!(isForwardRange, R))
|
||||
@property auto save()
|
||||
{
|
||||
import std.algorithm.mutation : move;
|
||||
typeof(this) result = this;
|
||||
foreach (i, Unused; R)
|
||||
auto saveSource(size_t len)()
|
||||
{
|
||||
auto saved = result.source[i].save;
|
||||
move(saved, result.source[i]);
|
||||
import std.typecons : tuple;
|
||||
static if (len == 0)
|
||||
{
|
||||
return tuple();
|
||||
}
|
||||
return result;
|
||||
else
|
||||
{
|
||||
return saveSource!(len - 1)() ~
|
||||
tuple(source[len - 1].save);
|
||||
}
|
||||
}
|
||||
return Result(saveSource!(R.length).expand);
|
||||
}
|
||||
|
||||
void popFront()
|
||||
|
@ -1523,13 +1529,9 @@ private struct ChooseResult(R1, R2)
|
|||
static if (isForwardRange!R1 && isForwardRange!R2)
|
||||
@property auto save()
|
||||
{
|
||||
auto result = this;
|
||||
actOnChosen!((ref r) {
|
||||
import std.algorithm.mutation : move;
|
||||
auto saved = r.save;
|
||||
move(saved, r);
|
||||
})(result);
|
||||
return result;
|
||||
return r1Chosen
|
||||
? ChooseResult(r1Chosen, r1.save, r2)
|
||||
: ChooseResult(r1Chosen, r1, r2.save);
|
||||
}
|
||||
|
||||
@property void front(T)(T v)
|
||||
|
@ -1844,14 +1846,20 @@ if (Rs.length > 1 && allSatisfy!(isInputRange, staticMap!(Unqual, Rs)))
|
|||
static if (allSatisfy!(isForwardRange, staticMap!(Unqual, Rs)))
|
||||
@property auto save()
|
||||
{
|
||||
import std.algorithm.mutation : move;
|
||||
Result result = this;
|
||||
foreach (i, Unused; Rs)
|
||||
auto saveSource(size_t len)()
|
||||
{
|
||||
auto saved = result.source[i].save;
|
||||
move(saved, result.source[i]);
|
||||
import std.typecons : tuple;
|
||||
static if (len == 0)
|
||||
{
|
||||
return tuple();
|
||||
}
|
||||
return result;
|
||||
else
|
||||
{
|
||||
return saveSource!(len - 1)() ~
|
||||
tuple(source[len - 1].save);
|
||||
}
|
||||
}
|
||||
return Result(saveSource!(Rs.length).expand, _current);
|
||||
}
|
||||
|
||||
static if (allSatisfy!(hasLength, Rs))
|
||||
|
@ -3782,6 +3790,12 @@ if (isForwardRange!R && !isInfinite!R)
|
|||
_current = input.save;
|
||||
}
|
||||
|
||||
private this(R original, R current)
|
||||
{
|
||||
_original = original;
|
||||
_current = current;
|
||||
}
|
||||
|
||||
/// ditto
|
||||
@property auto ref front()
|
||||
{
|
||||
|
@ -3820,13 +3834,8 @@ if (isForwardRange!R && !isInfinite!R)
|
|||
/// ditto
|
||||
@property Cycle save()
|
||||
{
|
||||
import std.algorithm.mutation : move;
|
||||
//No need to call _original.save, because Cycle never actually modifies _original
|
||||
Cycle ret = this;
|
||||
ret._original = _original;
|
||||
auto saved = _current.save;
|
||||
move(saved, _current);
|
||||
return ret;
|
||||
return Cycle(_original, _current.save);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue