// TEMPLATE CONSTRUCTOR pair::pair(tuple, tuple, sequence, sequence)
template<class _Ty1,
class _Ty2>
template<class _Tuple1,
class _Tuple2,
size_t... _Indexes1,
size_t... _Indexes2> inline
pair<_Ty1, _Ty2>::pair(_Tuple1& _Val1,
_Tuple2& _Val2,
index_sequence<_Indexes1...>,
index_sequence<_Indexes2...>)
: first(_STD get<_Indexes1>(_STD move(_Val1))...),
second(_STD get<_Indexes2>(_STD move(_Val2))...)
{ // construct from pair of tuples
}
// TEMPLATE CONSTRUCTOR pair::pair(piecewise_construct_t, tuple, tuple)
template<class _Ty1,
class _Ty2>
template<class... _Types1,
class... _Types2> inline
pair<_Ty1, _Ty2>::pair(piecewise_construct_t,
tuple<_Types1...> _Val1,
tuple<_Types2...> _Val2)
: pair(_Val1, _Val2,
index_sequence_for<_Types1...>(),
index_sequence_for<_Types2...>())
{ // construct from pair of tuples
}
The above is the source code of tuple in VisualStudio. It is the piece-wise constructor of std::pair. The second constructor calls the first one. In the first constructor, data member first and second are initialized by
first(_STD get<_Indexes1>(_STD move(_Val1))...), second(_STD get<_Indexes2>(_STD move(_Val2))...)
I don't understand why std::move can be used here. What if some arguments in the tuple is not an rvalue? Wouldn't it make arguments that are lvalues to become rvalues and invoke unintended constructor of first and second?
Aucun commentaire:
Enregistrer un commentaire