what happens to std::vector storage after std::move() [duplicate]












3















This question already has an answer here:




  • What can I do with a moved-from object?

    2 answers




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?










share|improve this question













marked as duplicate by Mike Vine, Jonny Henly, πάντα ῥεῖ c++
Users with the  c++ badge can single-handedly close c++ questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 20 at 17:54


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.











  • 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.
    Nov 20 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. 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 at 19:38


















3















This question already has an answer here:




  • What can I do with a moved-from object?

    2 answers




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?










share|improve this question













marked as duplicate by Mike Vine, Jonny Henly, πάντα ῥεῖ c++
Users with the  c++ badge can single-handedly close c++ questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 20 at 17:54


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.











  • 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.
    Nov 20 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. 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 at 19:38
















3












3








3








This question already has an answer here:




  • What can I do with a moved-from object?

    2 answers




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?










share|improve this question














This question already has an answer here:




  • What can I do with a moved-from object?

    2 answers




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?





This question already has an answer here:




  • What can I do with a moved-from object?

    2 answers








c++ stl






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 20 at 17:40









debonair

96821543




96821543




marked as duplicate by Mike Vine, Jonny Henly, πάντα ῥεῖ c++
Users with the  c++ badge can single-handedly close c++ questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 20 at 17:54


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by Mike Vine, Jonny Henly, πάντα ῥεῖ c++
Users with the  c++ badge can single-handedly close c++ questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 20 at 17:54


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.










  • 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.
    Nov 20 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. 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 at 19:38
















  • 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.
    Nov 20 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. 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 at 19:38










2




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.
Nov 20 at 17:46




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.
Nov 20 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. 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 at 19:38






The content of a vector which was the source of a move assignment or moved copy constructor can be guessed from the 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 at 19:38














1 Answer
1






active

oldest

votes


















1














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.






share|improve this answer





















  • 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
    – user463035818
    Nov 20 at 17:50












  • @user463035818 Well that's true but can't make guarantees on it ^^
    – Sombrero Chicken
    Nov 20 at 17:52


















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














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.






share|improve this answer





















  • 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
    – user463035818
    Nov 20 at 17:50












  • @user463035818 Well that's true but can't make guarantees on it ^^
    – Sombrero Chicken
    Nov 20 at 17:52
















1














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.






share|improve this answer





















  • 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
    – user463035818
    Nov 20 at 17:50












  • @user463035818 Well that's true but can't make guarantees on it ^^
    – Sombrero Chicken
    Nov 20 at 17:52














1












1








1






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.






share|improve this answer












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.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 20 at 17:47









Sombrero Chicken

23.2k33076




23.2k33076












  • 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
    – user463035818
    Nov 20 at 17:50












  • @user463035818 Well that's true but can't make guarantees on it ^^
    – Sombrero Chicken
    Nov 20 at 17:52


















  • 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
    – user463035818
    Nov 20 at 17:50












  • @user463035818 Well that's true but can't make guarantees on it ^^
    – Sombrero Chicken
    Nov 20 at 17:52
















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
– user463035818
Nov 20 at 17:50






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
– user463035818
Nov 20 at 17:50














@user463035818 Well that's true but can't make guarantees on it ^^
– Sombrero Chicken
Nov 20 at 17:52




@user463035818 Well that's true but can't make guarantees on it ^^
– Sombrero Chicken
Nov 20 at 17:52



Popular posts from this blog

Ottavio Pratesi

Tricia Helfer

15 giugno