mirror of
https://github.com/dlang/phobos.git
synced 2025-05-07 03:27:03 +03:00
fix Issue 5939 - Cannot copy std.algorithm.map
Move out Voldemort types to modle level.
This commit is contained in:
parent
0a5c88daf3
commit
cedddcd23e
2 changed files with 298 additions and 301 deletions
|
@ -377,17 +377,21 @@ template map(fun...) if (fun.length >= 1)
|
|||
alias unaryFun!fun _fun;
|
||||
}
|
||||
|
||||
struct Result
|
||||
{
|
||||
return MapResult!(_fun, Range)(r);
|
||||
}
|
||||
}
|
||||
|
||||
private struct MapResult(alias fun, Range)
|
||||
{
|
||||
alias Unqual!Range R;
|
||||
alias typeof(_fun(.ElementType!R.init)) ElementType;
|
||||
//alias typeof(fun(.ElementType!R.init)) ElementType;
|
||||
R _input;
|
||||
|
||||
static if (isBidirectionalRange!R)
|
||||
{
|
||||
@property auto ref back()
|
||||
{
|
||||
return _fun(_input.back);
|
||||
return fun(_input.back);
|
||||
}
|
||||
|
||||
void popBack()
|
||||
|
@ -421,14 +425,14 @@ template map(fun...) if (fun.length >= 1)
|
|||
|
||||
@property auto ref front()
|
||||
{
|
||||
return _fun(_input.front);
|
||||
return fun(_input.front);
|
||||
}
|
||||
|
||||
static if (isRandomAccessRange!R)
|
||||
{
|
||||
auto ref opIndex(size_t index)
|
||||
{
|
||||
return _fun(_input[index]);
|
||||
return fun(_input[index]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -457,10 +461,6 @@ template map(fun...) if (fun.length >= 1)
|
|||
result._input = result._input.save;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return Result(r);
|
||||
}
|
||||
}
|
||||
|
||||
unittest
|
||||
|
@ -1092,15 +1092,19 @@ template filter(alias pred) if (is(typeof(unaryFun!pred)))
|
|||
{
|
||||
auto filter(Range)(Range rs) if (isInputRange!(Unqual!Range))
|
||||
{
|
||||
struct FilteredRange
|
||||
{
|
||||
return FilterResult!(unaryFun!pred, Range)(rs);
|
||||
}
|
||||
}
|
||||
|
||||
private struct FilterResult(alias pred, Range)
|
||||
{
|
||||
alias Unqual!Range R;
|
||||
R _input;
|
||||
|
||||
this(R r)
|
||||
{
|
||||
_input = r;
|
||||
while (!_input.empty && !unaryFun!pred(_input.front))
|
||||
while (!_input.empty && !pred(_input.front))
|
||||
{
|
||||
_input.popFront();
|
||||
}
|
||||
|
@ -1122,7 +1126,7 @@ template filter(alias pred) if (is(typeof(unaryFun!pred)))
|
|||
do
|
||||
{
|
||||
_input.popFront();
|
||||
} while (!_input.empty && !unaryFun!pred(_input.front));
|
||||
} while (!_input.empty && !pred(_input.front));
|
||||
}
|
||||
|
||||
@property auto ref front()
|
||||
|
@ -1137,10 +1141,6 @@ template filter(alias pred) if (is(typeof(unaryFun!pred)))
|
|||
return typeof(this)(_input);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return FilteredRange(rs);
|
||||
}
|
||||
}
|
||||
|
||||
unittest
|
||||
|
@ -1256,17 +1256,20 @@ template filterBidirectional(alias pred)
|
|||
{
|
||||
auto filterBidirectional(Range)(Range r) if (isBidirectionalRange!(Unqual!Range))
|
||||
{
|
||||
struct Result
|
||||
{
|
||||
return FilterBidiResult!(unaryFun!pred, Range)(r);
|
||||
}
|
||||
}
|
||||
|
||||
private struct FilterBidiResult(alias pred, Range)
|
||||
{
|
||||
alias Unqual!Range R;
|
||||
alias unaryFun!pred predFun;
|
||||
R _input;
|
||||
|
||||
this(R r)
|
||||
{
|
||||
_input = r;
|
||||
while (!_input.empty && !predFun(_input.front)) _input.popFront();
|
||||
while (!_input.empty && !predFun(_input.back)) _input.popBack();
|
||||
while (!_input.empty && !pred(_input.front)) _input.popFront();
|
||||
while (!_input.empty && !pred(_input.back)) _input.popBack();
|
||||
}
|
||||
|
||||
@property bool empty() { return _input.empty; }
|
||||
|
@ -1276,7 +1279,7 @@ template filterBidirectional(alias pred)
|
|||
do
|
||||
{
|
||||
_input.popFront();
|
||||
} while (!_input.empty && !predFun(_input.front));
|
||||
} while (!_input.empty && !pred(_input.front));
|
||||
}
|
||||
|
||||
@property auto ref front()
|
||||
|
@ -1289,7 +1292,7 @@ template filterBidirectional(alias pred)
|
|||
do
|
||||
{
|
||||
_input.popBack();
|
||||
} while (!_input.empty && !predFun(_input.back));
|
||||
} while (!_input.empty && !pred(_input.back));
|
||||
}
|
||||
|
||||
@property auto ref back()
|
||||
|
@ -1299,13 +1302,7 @@ template filterBidirectional(alias pred)
|
|||
|
||||
@property auto save()
|
||||
{
|
||||
Result result;
|
||||
result._input = _input.save;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return Result(r);
|
||||
return typeof(this)(_input.save);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2211,11 +2208,13 @@ unittest
|
|||
auto splitter(alias isTerminator, Range)(Range input)
|
||||
if (is(typeof(unaryFun!(isTerminator)(ElementType!(Range).init))))
|
||||
{
|
||||
struct Result
|
||||
{
|
||||
return SplitterResult!(unaryFun!isTerminator, Range)(input);
|
||||
}
|
||||
|
||||
private struct SplitterResult(alias isTerminator, Range)
|
||||
{
|
||||
private Range _input;
|
||||
private size_t _end;
|
||||
private alias unaryFun!isTerminator _isTerminator;
|
||||
|
||||
this(Range input)
|
||||
{
|
||||
|
@ -2227,7 +2226,7 @@ if (is(typeof(unaryFun!(isTerminator)(ElementType!(Range).init))))
|
|||
else
|
||||
{
|
||||
// Chase first terminator
|
||||
while (_end < _input.length && !_isTerminator(_input[_end]))
|
||||
while (_end < _input.length && !isTerminator(_input[_end]))
|
||||
{
|
||||
++_end;
|
||||
}
|
||||
|
@ -2271,17 +2270,17 @@ if (is(typeof(unaryFun!(isTerminator)(ElementType!(Range).init))))
|
|||
_end = _end.max;
|
||||
return;
|
||||
}
|
||||
if (!_isTerminator(_input.front))
|
||||
if (!isTerminator(_input.front))
|
||||
{
|
||||
// Found a legit next field
|
||||
break;
|
||||
}
|
||||
_input.popFront();
|
||||
}
|
||||
assert(!_input.empty && !_isTerminator(_input.front));
|
||||
assert(!_input.empty && !isTerminator(_input.front));
|
||||
// Prepare _end
|
||||
_end = 1;
|
||||
while (_end < _input.length && !_isTerminator(_input[_end]))
|
||||
while (_end < _input.length && !isTerminator(_input[_end]))
|
||||
{
|
||||
++_end;
|
||||
}
|
||||
|
@ -2296,10 +2295,8 @@ if (is(typeof(unaryFun!(isTerminator)(ElementType!(Range).init))))
|
|||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Result(input);
|
||||
}
|
||||
|
||||
unittest
|
||||
{
|
||||
auto L = iota(1L, 10L);
|
||||
|
@ -2639,8 +2636,11 @@ assert(equal(uniq(arr), [ 1, 2, 3, 4, 5 ][]));
|
|||
auto uniq(alias pred = "a == b", Range)(Range r)
|
||||
if (isInputRange!Range && is(typeof(binaryFun!pred(r.front, r.front)) == bool))
|
||||
{
|
||||
struct Result
|
||||
{
|
||||
return UniqResult!(binaryFun!pred, Range)(r);
|
||||
}
|
||||
|
||||
private struct UniqResult(alias pred, Range)
|
||||
{
|
||||
Range _input;
|
||||
|
||||
this(Range input)
|
||||
|
@ -2660,7 +2660,7 @@ if (isInputRange!Range && is(typeof(binaryFun!pred(r.front, r.front)) == bool))
|
|||
{
|
||||
_input.popFront();
|
||||
}
|
||||
while (!_input.empty && binaryFun!(pred)(last, _input.front));
|
||||
while (!_input.empty && pred(last, _input.front));
|
||||
}
|
||||
|
||||
@property ElementType!Range front() { return _input.front; }
|
||||
|
@ -2674,7 +2674,7 @@ if (isInputRange!Range && is(typeof(binaryFun!pred(r.front, r.front)) == bool))
|
|||
{
|
||||
_input.popBack();
|
||||
}
|
||||
while (!_input.empty && binaryFun!pred(last, _input.back));
|
||||
while (!_input.empty && pred(last, _input.back));
|
||||
}
|
||||
|
||||
@property ElementType!Range back() { return _input.back; }
|
||||
|
@ -2695,9 +2695,6 @@ if (isInputRange!Range && is(typeof(binaryFun!pred(r.front, r.front)) == bool))
|
|||
return typeof(this)(_input.save);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Result(r);
|
||||
}
|
||||
|
||||
unittest
|
||||
|
|
|
@ -757,7 +757,7 @@ Example:
|
|||
@trusted int sub(int a, int b) {return a-b;}
|
||||
@system int mul(int a, int b) {return a*b;}
|
||||
|
||||
htatic assert( isSafe!add);
|
||||
static assert( isSafe!add);
|
||||
static assert( isSafe!sub);
|
||||
static assert(!isSafe!mul);
|
||||
--------------------
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue