[patch] : Adding move symantics to vector

Howard Hinnant hinnant@twcny.rr.com
Fri Sep 9 00:19:00 GMT 2005


On Sep 8, 2005, at 7:43 PM, chris jefferson wrote:

> 1) Find the person who put vector<bool> in the standard and beat them.

Oh, this one is quite exciting. ;-)

> 2) Add a new overload of __move
>
> template<class _Tp>
>     inline const _Tp&
>     __move(const _Tp& __in)
>     { return __in; }
>
> so temporaries are passed stright through.
>
> 3) change __move to use enable_if, something like:
>
> template<class _Tp>
> inline __rvalref<_Tp>
> __move(__enable_if<_Tp &, std::__is_moveable<_Tp>::value> __in)
> { return __rvalref<_Tp>(__in); }
>
> template<class _Tp>
> inline const _Tp&
> __move(__enable_if<const _Tp &, !std::__is_moveable<_Tp>::value> __in)
> { return __in; }

Have you considered:

4)  get the rvalue reference implemented in the compiler, perhaps under 
a #pragma, and use that?  Your clients could then say:  wow, look what 
happens when I turn this pragma on!  And the implementation difficulty 
in the lib could drop by an order of magnitude.

I've done both lib solutions (2 and 3) and a hard core 4 (if you want 
move, you've got to change the language).  To date I'm happiest from a 
maintenance point of view with 4.  But it requires a longer point of 
view and more cooperation with compiler implementors (both good 
things).

-Howard



More information about the Libstdc++ mailing list