1

cppreference says this about std::set nodes:

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.

The same rule applies to all STL node-based containers.

Why did the standard make that decision?

It is especially disturbing to have a reference that is "valid but not usable". Does it occur in other circumstances?

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Meatboy 106
  • 196
  • 7

1 Answers1

0

The related questions section lead me to that answer to the exact same question.

TL;DR: Introducing mutability and allowing the use of references at the same time would be a violation of the strict aliasing rule.

Meatboy 106
  • 196
  • 7