std.container.RedBlackTree versus C++ std::set
Steven Schveighoffer
schveiguy at yahoo.com
Thu Feb 14 11:31:36 PST 2013
On Thu, 14 Feb 2013 13:45:30 -0500, Rob T <alanb at ucora.com> wrote:
> When I look at the std.container source code, it seems that the payload
> element is passed by value multiple times unnecessarily, so to minimize
> copy construction you'll have to implement element as a class and
> implement a dup function for it.
>
> I expect performance will increase substantially even with the extra
> heap allocations.
>
> Alternatively, you can implement your own version of RedBlackTree with
> pass by ref optimizations for insertion of struct elements.
If it was pass by ref, then rbt.insert(5) would not work. And in fact, I
wouldn't want things passed by ref if the element is int. I have to
admit, I did not consider expensive postblits when I designed it. Almost
all my testing is with integer types.
Unfortunately, D is in this state where taking a ref parameter means
strictly lvalue. So passing rvalues will not work. D does not have the
notion that C++ has where const type& can accept both rvalue and lvalue.
We desperately need something similar.
-Steve
More information about the Digitalmars-d-learn
mailing list