If you don't understand the implementation of
move() for now, it's not a problem.
You can treat it as a black box - you don't need to know how it works to use it properly.
Anyways I'm not certain I can explain this completely without an idea of how much C++ you're familiar with.
move()
in particular is really complicated.
There are 2 parts to the above. The first is the class template
remove_reference. For any type T, the type
typename remove_reference<T>::type is just
T without any reference qualifiers on it.
For example, if
T is an
lvalue reference type, like
int&, then
typename remove_reference<T>::type is
int. If
T is an
rvalue reference type, like
double&&, then the type
typename remove_reference<T>::type is
double. Otherwise, if
T is any other type like
char const* or
void(int), then
typename remove_reference<T>::type is
char const* or
void(int), respectively.
remove_reference is an example of a
meta-function. It relies on
template partial specialization. That's part of chapter 25 in TC++PL.
http://en.cppreference.com/w/cpp/language/partial_specialization
The second part is
move() itself.
1 2 3
|
template <typename T>
constexpr typename remove_reference<T>::type&& move(T&& x) noexcept
{ return (typename remove_reference<T>::type&&) x; }
|
It relies on the implicit creation of reference-to-references, and a bunch of subtleties about template argument deduction.
Thomas Becker explains it much better than I can, in this well-known article:
http://thbecker.net/articles/rvalue_references/section_01.html
But before you read that, you might watch this talk:
https://channel9.msdn.com/Shows/Going+Deep/Cpp-and-Beyond-2012-Scott-Meyers-Universal-References-in-Cpp11
and/or read this:
https://isocpp.org/blog/2012/11/universal-references-in-c11-scott-meyers
With the minor caveat that the invented term "universal references" are actually called "forwarding references".