Bug 8947 – redBlackTree() of fixed size arrays

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2012-11-02T12:40:52Z
Last change time
2019-12-09T10:58:56Z
Keywords
accepts-invalid, rejects-valid
Assigned to
No Owner
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2012-11-02T12:40:52Z
I think redBlackTree() has problems with fixed size arrays: import std.container: redBlackTree, RedBlackTree; void main() { int[2] a; auto t1 = new RedBlackTree!(typeof(a)); t1.stableInsert(a); // OK auto t2 = redBlackTree(a); t2.stableInsert(a); // Error t2.stableInsert(1); // No error, but it's wrong } DMD 2.061alpha gives: test.d(7): Error: template std.container.RedBlackTree!(int).RedBlackTree.stableInsert does not match any function template declaration ...\dmd2\src\phobos\std\container.d(5834): Error: template std.container.RedBlackTree!(int).RedBlackTree.stableInsert cannot deduce template function from argument types !()(int[2u])
Comment #1 by tetyys — 2017-04-09T07:17:40Z
It's because you're calling https://github.com/dlang/phobos/blob/master/std/container/rbtree.d#L1836 which resolves you to having tree of integers, thus "t2.stableInsert(1)" is not wrong. To have a tree of array of integers, do "redBlackTree([ a ])".
Comment #2 by bugzilla — 2019-12-09T10:58:56Z
t2 has elements of type int, while a is of type int[2]. You can't mix them.