In the STL implementation of VS10 there is the following code for a variant of std::swap():
// TEMPLATE FUNCTION _Move
template<class _Ty> inline
typename tr1::_Remove_reference<_Ty>::_Type&&
_Move(_Ty&& _Arg)
{ // forward _Arg as movable
return ((typename tr1::_Remove_reference<_Ty>::_Type&&)_Arg);
}
// TEMPLATE FUNCTION swap (from <algorithm>)
template<class _Ty> inline
void swap(_Ty& _Left, _Ty& _Right)
{ // exchange values stored at _Left and _Right
_Ty _Tmp = _Move(_Left);
_Left = _Move(_Right);
_Right = _Move(_Tmp);
}
The cast to (typename tr1::_Remove_reference<_Ty>::_Type&&)
in _Move() is the source of my question.
In this context _Remove_reference
is defined as follows:
// TEMPLATE _Remove_reference
template<class _Ty>
struct _Remove_reference
{ // remove reference
typedef _Ty _Type;
};
What does _Remove_reference do, and why? Furthermore, what does && do here, and how is it termed?