what happens to std::vector storage after std::move() [duplicate]
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?
c++ stl
marked as duplicate by Mike Vine, Jonny Henly, πάντα ῥεῖ
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.
add a comment |
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?
c++ stl
marked as duplicate by Mike Vine, Jonny Henly, πάντα ῥεῖ
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
add a comment |
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?
c++ stl
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
c++ stl
asked Nov 20 '18 at 17:40
debonairdebonair
97021543
97021543
marked as duplicate by Mike Vine, Jonny Henly, πάντα ῥεῖ
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, πάντα ῥεῖ
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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.
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
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
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
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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