mirror of
https://github.com/dlang/phobos.git
synced 2025-05-03 08:30:33 +03:00
Merge pull request #4887 from Superstar64/joiner_assign_front
made joiner.front assignable
This commit is contained in:
commit
fc37e0f750
1 changed files with 60 additions and 0 deletions
|
@ -2447,6 +2447,21 @@ if (isInputRange!RoR && isInputRange!(ElementType!RoR))
|
||||||
return copy;
|
return copy;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static if (hasAssignableElements!(ElementType!RoR))
|
||||||
|
{
|
||||||
|
@property void front(ElementType!(ElementType!RoR) element)
|
||||||
|
{
|
||||||
|
assert(!empty, "Attempting to assign to front of an empty joiner.");
|
||||||
|
_current.front = element;
|
||||||
|
}
|
||||||
|
|
||||||
|
@property void front(ref ElementType!(ElementType!RoR) element)
|
||||||
|
{
|
||||||
|
assert(!empty, "Attempting to assign to front of an empty joiner.");
|
||||||
|
_current.front = element;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return Result(r);
|
return Result(r);
|
||||||
}
|
}
|
||||||
|
@ -2606,6 +2621,51 @@ if (isInputRange!RoR && isInputRange!(ElementType!RoR))
|
||||||
assert(str == "abcd");
|
assert(str == "abcd");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@safe unittest
|
||||||
|
{
|
||||||
|
import std.range : repeat;
|
||||||
|
|
||||||
|
class AssignableRange
|
||||||
|
{
|
||||||
|
@safe:
|
||||||
|
int element;
|
||||||
|
@property int front()
|
||||||
|
{
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
|
||||||
|
enum empty = false;
|
||||||
|
|
||||||
|
void popFront()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
@property void front(int newValue)
|
||||||
|
{
|
||||||
|
element = newValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static assert(isInputRange!AssignableRange);
|
||||||
|
static assert(is(ElementType!AssignableRange == int));
|
||||||
|
static assert(hasAssignableElements!AssignableRange);
|
||||||
|
static assert(!hasLvalueElements!AssignableRange);
|
||||||
|
|
||||||
|
auto range = new AssignableRange();
|
||||||
|
assert(range.element == 0);
|
||||||
|
|
||||||
|
auto joined = joiner(repeat(range));
|
||||||
|
joined.front = 5;
|
||||||
|
assert(range.element == 5);
|
||||||
|
assert(joined.front == 5);
|
||||||
|
|
||||||
|
joined.popFront;
|
||||||
|
int byRef = 7;
|
||||||
|
joined.front = byRef;
|
||||||
|
assert(range.element == byRef);
|
||||||
|
assert(joined.front == byRef);
|
||||||
|
}
|
||||||
|
|
||||||
/++
|
/++
|
||||||
Implements the homonym function (also known as $(D accumulate), $(D
|
Implements the homonym function (also known as $(D accumulate), $(D
|
||||||
compress), $(D inject), or $(D foldl)) present in various programming
|
compress), $(D inject), or $(D foldl)) present in various programming
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue