On Thursday, 14 February 2013 at 19:31:36 UTC, Steven
Schveighoffer wrote:
On Thu, 14 Feb 2013 13:45:30 -0500, Rob T <al...@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
There are discussions for such thing for almost a year - but
nothing has changed so far.