Is the front address of std::vector move invariant?

  • A+

In the following snippet:

std::vector<double> a(100, 4.2); auto* a_ptr =;  auto b = std::move(a); auto* b_ptr =;  std::cout << ((b_ptr == a_ptr) ? "TRUE" : "FALSE") << '/n'; 

does the C++ standard guarantee that b_ptr is always equal to a_ptr after std::move? Running the code on wandbox prints TRUE.


From :

After container move construction (overload (6)), references, pointers, and iterators (other than the end iterator) to other remain valid, but refer to elements that are now in *this. The current standard makes this guarantee via the blanket statement in §23.2.1[container.requirements.general]/12, and a more direct guarantee is under consideration via LWG 2321.

Pointers to elements are not invalidated, including pointers to the first element.


:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: