This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [patch] : Adding move symantics to vector
Paolo Carlini wrote:
>chris jefferson wrote:
>
>
>
>>My first thought was "I bet it's that damn vector<bool> again". While it
>>isn't, I have discovered that all the "move semanticed" algorithms now
>>don't work with vector<bool>s. Of course, as discussed previously they
>>don't have to, but also it would be nice if they did. I'll have a ponder :)
>>
>>
>>
>>
>Hum, maybe now I see the real issue, it's the return type of operator*()
>for vector<bool>::iterator, right? An I have been wondering for a couple
>of days why the __move that you designed takes a & instead of a const &...
>
>
>
Yes, sorry, I should have been clearer :)
the problem is when we actually apply moving, clearly we need a
non-const reference to the thing we are moving from, as we intend to
change it. When not moving we can use a const &.
I have three ways to solve this, all are fine in my opinion. While I
personally like enable_if, I think (2) is probably the least exciting
option, and therefore most likely to work.
1) Find the person who put vector<bool> in the standard and beat them.
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; }