[Issue 17519] New: RedBlackTree doesn't like const/immutable elements
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Sat Jun 17 14:56:21 PDT 2017
https://issues.dlang.org/show_bug.cgi?id=17519
Issue ID: 17519
Summary: RedBlackTree doesn't like const/immutable elements
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: minor
Priority: P1
Component: phobos
Assignee: nobody at puremagic.com
Reporter: ag0aep6g at gmail.com
Simple examples where immutable/const is meaningless:
----
import std.container.rbtree: RedBlackTree;
void main()
{
RedBlackTree!(immutable int) t1; /* fails; should compile */
RedBlackTree!(const int) t2; /* fails; should compile */
}
----
It matters when the element type has indirections:
----
import std.algorithm: map;
import std.container.rbtree: RedBlackTree;
void main()
{
static struct S { int* p; }
auto t3 = new RedBlackTree!(immutable S, (a, b) => *a.p < *b.p);
/* fails; should compile */
t3.insert([1, 2, 3].map!(x => immutable S(new int(x))));
static assert(!__traits(compiles, *t3.front.p = 4));
}
----
--
More information about the Digitalmars-d-bugs
mailing list