c++stloperator-keywordmemory-address

C++ Double Address Operator? (&&)


I'm reading STL source code and I have no idea what && address operator is supposed to do. Here is a code example from stl_vector.h:

vector&
operator=(vector&& __x) // <-- Note double ampersands here
{
    // NB: DR 675.
    this->clear();
    this->swap(__x); 
    return *this;
}

Does "Address of Address" make any sense? Why does it have two address operators instead of just one?


Solution

  • This is C++11 code. In C++11, the && token can be used to mean an "rvalue reference".