K
Krzysztof Poc
Hi
I have a question about move semantic implementation in g++.
I extracted the following code right from g++. I tested it and it
works
fine. Unfortunately I don't understand it.
I read that "move" may take both lvalue and rvalue. In the
implementation
below I can see that move may take rvalue only (_Tp&& as an argument).
On the
other hand when I tested
it I found that below move implementation may take both rvalue and
lvalue (as
written in a documentation). So
please explain me what is incorrect in my understanding.
Another thing that I don't understand is the trick with a
remove_reference.
I read in a documentation of move that it returns the rvalue. Keeping
in mind
that information I assumed that only the third definition of a
remove_reference
structure in a below example is required. Unfortunately it turns out
that all 3
implementations are required for the code to compile successfully.
Could you
please explain me why is that.
thanks in advance
template<typename _Tp>
struct remove_reference
{
typedef _Tp type;
};
template<typename _Tp>
struct remove_reference<_Tp&>
{
typedef _Tp type;
};
template<typename _Tp>
struct remove_reference<_Tp&&>
{
typedef _Tp type;
};
template<typename _Tp>
inline typename remove_reference<_Tp>::type&&
move(_Tp&& __t)
{
return __t;
}
I have a question about move semantic implementation in g++.
I extracted the following code right from g++. I tested it and it
works
fine. Unfortunately I don't understand it.
I read that "move" may take both lvalue and rvalue. In the
implementation
below I can see that move may take rvalue only (_Tp&& as an argument).
On the
other hand when I tested
it I found that below move implementation may take both rvalue and
lvalue (as
written in a documentation). So
please explain me what is incorrect in my understanding.
Another thing that I don't understand is the trick with a
remove_reference.
I read in a documentation of move that it returns the rvalue. Keeping
in mind
that information I assumed that only the third definition of a
remove_reference
structure in a below example is required. Unfortunately it turns out
that all 3
implementations are required for the code to compile successfully.
Could you
please explain me why is that.
thanks in advance
template<typename _Tp>
struct remove_reference
{
typedef _Tp type;
};
template<typename _Tp>
struct remove_reference<_Tp&>
{
typedef _Tp type;
};
template<typename _Tp>
struct remove_reference<_Tp&&>
{
typedef _Tp type;
};
template<typename _Tp>
inline typename remove_reference<_Tp>::type&&
move(_Tp&& __t)
{
return __t;
}