3

I am calling std::vector.reserve() then I call std::move() on that vector object. Do I need to allocate space again? Does move changes the capacity of the vector?

debonair
  • 2,505
  • 4
  • 33
  • 73
  • 2
    `std::move` is just a cast. It does nothing to the object. It onky changes the type of the reference. You are interested in the subsequent move constructor/move assignment. – n. m. could be an AI Nov 20 '18 at 17:46
  • The content of a vector which was the source of a move assignment or moved copy constructor can be guessed from the [allocator requirements](http://eel.is/c++draft/allocator.requirements). All implementation do their best to avoid unnecessary memory allocation, so in practice, if the allocator allowes it, the moved from object has a null capacity. – Oliv Nov 20 '18 at 19:38

1 Answers1

2

The move constructor for vector[6] only guarantees that other.empty() == true (other being the moved-from object) after the move happens, it doesn't guarantee anything about the capacity() of the moved-from vector. So you can't be sure if it does or doesn't change the capacity.

So, to answer your question:

Does move changes the capacity of the vector?

This is unspecified.

Hatted Rooster
  • 35,759
  • 6
  • 62
  • 122