Skip to content

std.container.rbtree: Return range elements by ref #10755

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions std/container/rbtree.d
Original file line number Diff line number Diff line change
Expand Up @@ -679,15 +679,15 @@ private struct RBRange(N)
/**
* Returns the first element in the range
*/
@property Elem front()
ref @property Elem front()
{
return _begin.value;
}

/**
* Returns the last element in the range
*/
@property Elem back()
ref @property Elem back()
{
return _end.prev.value;
}
Expand Down Expand Up @@ -737,6 +737,10 @@ private struct RBRange(N)
* elements `a` and `b`, $(D less(a, b) == !less(b, a)). $(D less(a, a)) should
* always equal `false`.
*
* Care should also be taken to not modify elements in the tree (e.g. via `front` /
* `back`, which return by `ref`) in a way which would affect the order defined by
* the `less` predicate.
*
* If `allowDuplicates` is set to `true`, then inserting the same element more than
* once continues to add more elements. If it is `false`, duplicate elements are
* ignored on insertion. If duplicates are allowed, then new elements are
Expand Down Expand Up @@ -1036,7 +1040,7 @@ if (is(typeof(binaryFun!less(T.init, T.init))))
*
* Complexity: $(BIGOH 1)
*/
inout(Elem) front() inout
ref inout(Elem) front() inout
{
return _begin.value;
}
Expand All @@ -1046,7 +1050,7 @@ if (is(typeof(binaryFun!less(T.init, T.init))))
*
* Complexity: $(BIGOH log(n))
*/
inout(Elem) back() inout
ref inout(Elem) back() inout
{
return _end.prev.value;
}
Expand Down
Loading