mirror of
https://github.com/dlang/phobos.git
synced 2025-05-05 01:20:40 +03:00
Bug 4408: Ambiguity when using std.algorithm.splitter with generic ranges
This commit is contained in:
parent
096ddcad2a
commit
95122e68ab
1 changed files with 30 additions and 12 deletions
|
@ -1156,7 +1156,7 @@ public:
|
||||||
assert(!empty);
|
assert(!empty);
|
||||||
if (_frontLength == _unComputed)
|
if (_frontLength == _unComputed)
|
||||||
{
|
{
|
||||||
_frontLength = _input.indexOf(_separator);
|
_frontLength = indexOf(_input, _separator);
|
||||||
if (_frontLength == -1) _frontLength = _input.length;
|
if (_frontLength == -1) _frontLength = _input.length;
|
||||||
}
|
}
|
||||||
return _input[0 .. _frontLength];
|
return _input[0 .. _frontLength];
|
||||||
|
@ -1177,7 +1177,7 @@ public:
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_input = _input[_frontLength .. $];
|
_input = _input[_frontLength .. _input.length];
|
||||||
skipOver(_input, _separator) || assert(false);
|
skipOver(_input, _separator) || assert(false);
|
||||||
_frontLength = _unComputed;
|
_frontLength = _unComputed;
|
||||||
}
|
}
|
||||||
|
@ -1224,14 +1224,21 @@ unittest
|
||||||
a = [ 0, 1 ];
|
a = [ 0, 1 ];
|
||||||
assert(equal(splitter(a, 0), [ [], [1] ][]));
|
assert(equal(splitter(a, 0), [ [], [1] ][]));
|
||||||
|
|
||||||
// foreach(DummyType; AllDummyRanges) { // Bug 4408
|
foreach(DummyType; AllDummyRanges) { // Bug 4408
|
||||||
// DummyType d;
|
static if(isRandomAccessRange!DummyType) {
|
||||||
// auto s = splitter(d, 5);
|
static assert(isBidirectionalRange!DummyType);
|
||||||
// assert(equal(s, [[1,2,3,4], [6,7,8,9,10]]));
|
DummyType d;
|
||||||
//
|
auto s = splitter(d, 5);
|
||||||
// auto s2 = splitter(d, [4, 5]);
|
assert(equal(s.front, [1,2,3,4]));
|
||||||
// assert(equal(s2, [[1,2,3], [6,7,8,9,10]]));
|
s.popFront();
|
||||||
// }
|
assert(equal(s.front, [6,7,8,9,10]));
|
||||||
|
|
||||||
|
|
||||||
|
auto s2 = splitter(d, [4, 5]);
|
||||||
|
assert(equal(s2.front, [1,2,3]));
|
||||||
|
assert(equal(s2.back, [6,7,8,9,10]));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1430,7 +1437,7 @@ struct Splitter(alias isTerminator, Range,
|
||||||
Slice = Select!(is(typeof(Range.init[0 .. 1])),
|
Slice = Select!(is(typeof(Range.init[0 .. 1])),
|
||||||
Range,
|
Range,
|
||||||
ElementType!(Range)[]))
|
ElementType!(Range)[]))
|
||||||
{
|
if(!is(isTerminator)) {
|
||||||
private Range _input;
|
private Range _input;
|
||||||
private size_t _end;
|
private size_t _end;
|
||||||
private alias unaryFun!isTerminator _isTerminator;
|
private alias unaryFun!isTerminator _isTerminator;
|
||||||
|
@ -1479,7 +1486,7 @@ struct Splitter(alias isTerminator, Range,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Skip over existing word
|
// Skip over existing word
|
||||||
_input = _input[_end .. $];
|
_input = _input[_end .. _input.length];
|
||||||
// Skip terminator
|
// Skip terminator
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
|
@ -1546,6 +1553,17 @@ unittest
|
||||||
compare(" ", [""]);
|
compare(" ", [""]);
|
||||||
|
|
||||||
static assert(isForwardRange!(typeof(splitter!"a == ' '"("ABC"))));
|
static assert(isForwardRange!(typeof(splitter!"a == ' '"("ABC"))));
|
||||||
|
|
||||||
|
foreach(DummyType; AllDummyRanges)
|
||||||
|
{
|
||||||
|
static if(isRandomAccessRange!DummyType)
|
||||||
|
{
|
||||||
|
auto rangeSplit = splitter!"a == 5"(DummyType.init);
|
||||||
|
assert(equal(rangeSplit.front, [1,2,3,4]));
|
||||||
|
rangeSplit.popFront();
|
||||||
|
assert(equal(rangeSplit.front, [6,7,8,9,10]));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// joiner
|
// joiner
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue