www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 17519] New: RedBlackTree doesn't like const/immutable elements

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 puremagic.com
          Reporter: ag0aep6g 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));
}
----

--
Jun 17