What pointer is valid but cannot be used?

  c++, iterator, pointers, standards, stl

From the cppref (emphasis is mine):

Extracting a node invalidates the iterators to the extracted element.
Pointers and references to the extracted element remain valid, but
cannot be used
while element is owned by a node handle: they become
usable if the element is inserted into a container.

However, the following code runs well:

#include <set>
#include <string>
#include <iostream>

using namespace std::literals;

int main()
{
    auto  coll = std::set<std::string>{"abc"s, "xyz"s};
    auto  pos  = coll.find("abc"s);
    auto* p    = &*pos;
    auto  nh   = coll.extract("abc"s);

    std::cout << *p << std::endl; // output "abc" as expected
}

See online demo

So, my question is:

What pointer is valid but cannot be used?

Source: Windows Questions C++

LEAVE A COMMENT