std.container.RedBlackTree versus C++ std::set

Ivan Kazmenko gassa at mail.ru
Wed Feb 13 15:33:26 PST 2013


P.S. More on C++ version:

> Personally, I don't see why at all we should call the copy 
> constructor more than once per element. I mean, if we intend to 
> build a generic data structure, we sure need an internal node 
> object with some extra bytes (internal references and counters) 
> per each element, at least in the case of a red-black tree. So 
> why don't we just bind each element to that internal node once 
> and for all, and then, as long as the node is in the structure, 
> use the data contained in it only by reference? What do we 
> achieve if we choose to use it by value somewhere?

Well, when I just changed
"bool operator < (const element other) const"
to
"bool operator < (const element & other) const"
in the C++ version of the program, it gave me the exact 100,000 
copy constructor calls which justifies the above paragraph. 
Ouch... I had hopes GCC -O2 optimizes such obvious cases; perhaps 
it's not that obvious from the compiler point of view.

-----
Ivan Kazmenko.


More information about the Digitalmars-d-learn mailing list