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?
            Asked
            
        
        
            Active
            
        
            Viewed 1,551 times
        
    3
            
            
         
    
    
        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 Answers
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
- 
                    not specified, though would be rather strange if a vector does not steal the actual memory when move constructed or if the moved from would allocate new memory – 463035818_is_not_an_ai Nov 20 '18 at 17:50
- 
                    @user463035818 Well that's true but can't make guarantees on it ^^ – Hatted Rooster Nov 20 '18 at 17:52