Guillaume Paris
Guillaume Paris

Reputation: 10539

c++ vector implementation - move constructor - move vs forward

Under MSVC2010 the definition of move constructor for vector class is the following :

vector(_Myt&& _Right)
    : _Mybase(_Right._Alval)
    {   // construct by moving _Right
    _Assign_rv(_STD forward<_Myt>(_Right));
    }

As there is also a definition of a copy constructor, I guess we never call vector(_Myt&& _Right) with a lvalue reference as argument.

So I'm wondering if here, this line :

_Assign_rv(_STD forward<_Myt>(_Right));

could be replace by :

_Assign_rv(_STD move<_Myt>(_Right));

with no side effect

Upvotes: 3

Views: 685

Answers (1)

R. Martinho Fernandes
R. Martinho Fernandes

Reputation: 234474

Yes, for a type without reference qualifiers T, both std::forward<T> and std::forward<T&&> are just fancy ways of saying std::move.

Upvotes: 4

Related Questions