c++c++11

Is it possible to move an item out of a std::set?


If I have an object that only allows move-only semantics - is it possible to move items from a set? I can't seem to find a way to do this.


Solution

  • Note: This is an answer for C++ versions prior to C++17

    No, it is not possible. There is no way to get non-const access to elements in a set, and move requires non-const references. Allowing non-const access would make it trivially easy to break the invariants for set.