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 '18 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 '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. 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


















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 '18 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 '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. 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
















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 '18 at 17:40









debonairdebonair

97021543




97021543




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 '18 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 '18 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 '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. 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
















  • 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 '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. 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










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 '18 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 '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. 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







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 '18 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 '18 at 17:50













  • @user463035818 Well that's true but can't make guarantees on it ^^

    – Sombrero Chicken
    Nov 20 '18 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 '18 at 17:50













  • @user463035818 Well that's true but can't make guarantees on it ^^

    – Sombrero Chicken
    Nov 20 '18 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 '18 at 17:50













  • @user463035818 Well that's true but can't make guarantees on it ^^

    – Sombrero Chicken
    Nov 20 '18 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 '18 at 17:47









Sombrero ChickenSombrero Chicken

23.7k33077




23.7k33077













  • 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 '18 at 17:50













  • @user463035818 Well that's true but can't make guarantees on it ^^

    – Sombrero Chicken
    Nov 20 '18 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 '18 at 17:50













  • @user463035818 Well that's true but can't make guarantees on it ^^

    – Sombrero Chicken
    Nov 20 '18 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 '18 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 '18 at 17:50















@user463035818 Well that's true but can't make guarantees on it ^^

– Sombrero Chicken
Nov 20 '18 at 17:52





@user463035818 Well that's true but can't make guarantees on it ^^

– Sombrero Chicken
Nov 20 '18 at 17:52



Popular posts from this blog

'app-layout' is not a known element: how to share Component with different Modules

android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

WPF add header to Image with URL pettitions [duplicate]