rvalue references in libstdc++

Howard Hinnant hhinnant@apple.com
Mon Apr 30 20:19:00 GMT 2007


On Apr 30, 2007, at 4:11 PM, Chris Jefferson wrote:

> Hello,
>
> I've been looking at updating the v7 branch to support "true" rvalue
> references. The code already there which implements it with a
> wrapper-hack will (purposefully) map very easily to the "true"
> semantics.
>
> Obviously it would be nice to avoid code duplication, but at the same
> time I assume the library will need to still function without rvalue
> references, in C++03 mode.
>
> There are as far as I can see only two real problems.
>
> 1) A bunch of new functions
> 2) References to std::move all over the place.
>
> Therefore, my plan is as follows:
>
> 1) Stick #ifdefs around the new functions
> 2) Define a macro, something like _GLIBCXX_MOVE, which is defined
> something like:
>
> #ifdef rvalrefs
> #define _GLIBCXX_MOVE(x) move(x)
> #else
> #define _GLIBCXX_MOVE(x) x
> #endif
>
> These two cases seem to cover 99% (possibly 100%) of the issues
> involving keeping the library working both with and without rvalue
> references. Obviously submitting this code is waiting on the rvalue
> reference support in the compiler itself.
>
> Comments?

When faced with this same challenge in the CodeWarrior library I had  
good luck with the technique outlined here:

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/ 
n1771.html#old_move

It is roughly equivalent to your plan.  The one advantage is that the  
ugliness is constrained to just the definition of move/forward  
instead of being spread everywhere these utilities are used.

-Howard



More information about the Libstdc++ mailing list