mirror of
https://github.com/dlang/phobos.git
synced 2025-04-28 14:10:30 +03:00
RedBlackTree.empty: const, .front/.back: inout (#7644)
* RedBlackTree.empty(): Annotated const RedBlackTree is a template, therefore all other qualifiers for empty(), length(), and opBinaryRight!"in" will be inferred: pure, nothrow, @safe, @nogc. * RedBlackTree.front, .back: inout
This commit is contained in:
parent
4d7e5829cb
commit
b0b64c3f41
1 changed files with 11 additions and 5 deletions
|
@ -964,7 +964,7 @@ if (is(typeof(binaryFun!less(T.init, T.init))))
|
||||||
* Check if any elements exist in the container. Returns `false` if at least
|
* Check if any elements exist in the container. Returns `false` if at least
|
||||||
* one element exists.
|
* one element exists.
|
||||||
*/
|
*/
|
||||||
@property bool empty()
|
@property bool empty() const // pure, nothrow, @safe, @nogc: are inferred
|
||||||
{
|
{
|
||||||
return _end.left is null;
|
return _end.left is null;
|
||||||
}
|
}
|
||||||
|
@ -1030,7 +1030,7 @@ if (is(typeof(binaryFun!less(T.init, T.init))))
|
||||||
*
|
*
|
||||||
* Complexity: $(BIGOH 1)
|
* Complexity: $(BIGOH 1)
|
||||||
*/
|
*/
|
||||||
Elem front()
|
inout(Elem) front() inout
|
||||||
{
|
{
|
||||||
return _begin.value;
|
return _begin.value;
|
||||||
}
|
}
|
||||||
|
@ -1040,7 +1040,7 @@ if (is(typeof(binaryFun!less(T.init, T.init))))
|
||||||
*
|
*
|
||||||
* Complexity: $(BIGOH log(n))
|
* Complexity: $(BIGOH log(n))
|
||||||
*/
|
*/
|
||||||
Elem back()
|
inout(Elem) back() inout
|
||||||
{
|
{
|
||||||
return _end.prev.value;
|
return _end.prev.value;
|
||||||
}
|
}
|
||||||
|
@ -2164,8 +2164,12 @@ if ( is(typeof(binaryFun!less((ElementType!Stuff).init, (ElementType!Stuff).init
|
||||||
@safe pure unittest
|
@safe pure unittest
|
||||||
{
|
{
|
||||||
const rt1 = redBlackTree(5,4,3,2,1);
|
const rt1 = redBlackTree(5,4,3,2,1);
|
||||||
static assert(is(typeof(rt1.length)));
|
void allQualifiers() pure nothrow @safe @nogc {
|
||||||
static assert(is(typeof(5 in rt1)));
|
assert(!rt1.empty);
|
||||||
|
assert(rt1.length == 5);
|
||||||
|
assert(5 in rt1);
|
||||||
|
}
|
||||||
|
allQualifiers();
|
||||||
|
|
||||||
static assert(is(typeof(rt1.upperBound(3).front) == const(int)));
|
static assert(is(typeof(rt1.upperBound(3).front) == const(int)));
|
||||||
import std.algorithm.comparison : equal;
|
import std.algorithm.comparison : equal;
|
||||||
|
@ -2179,7 +2183,9 @@ if ( is(typeof(binaryFun!less((ElementType!Stuff).init, (ElementType!Stuff).init
|
||||||
@safe pure unittest
|
@safe pure unittest
|
||||||
{
|
{
|
||||||
immutable rt1 = redBlackTree(5,4,3,2,1);
|
immutable rt1 = redBlackTree(5,4,3,2,1);
|
||||||
|
static assert(is(typeof(rt1.empty)));
|
||||||
static assert(is(typeof(rt1.length)));
|
static assert(is(typeof(rt1.length)));
|
||||||
|
static assert(is(typeof(5 in rt1)));
|
||||||
|
|
||||||
static assert(is(typeof(rt1.upperBound(3).front) == immutable(int)));
|
static assert(is(typeof(rt1.upperBound(3).front) == immutable(int)));
|
||||||
import std.algorithm.comparison : equal;
|
import std.algorithm.comparison : equal;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue