What is the result of assigning to std::vector::begin()?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I've a bit understanding about lvalue and rvalues. So as I know we cannot assign to an rvalue but non-const lvalue is ok.
#include <iostream>
#include <vector>
int main(){
std::vector<int> v{ 1, 2, 3, 4, 5 };
v.begin() = v.end() - 2;
std::cout << *v.begin() << std::endl; // 1
for (auto const& e : v)
std::cout << e << ", ";// 1, 2, 3, 4, 5,
std::cout << std::endl;
}
Why I can assign to begin()
but it does nothing on the elements?
c++ vector
New contributor
add a comment |
I've a bit understanding about lvalue and rvalues. So as I know we cannot assign to an rvalue but non-const lvalue is ok.
#include <iostream>
#include <vector>
int main(){
std::vector<int> v{ 1, 2, 3, 4, 5 };
v.begin() = v.end() - 2;
std::cout << *v.begin() << std::endl; // 1
for (auto const& e : v)
std::cout << e << ", ";// 1, 2, 3, 4, 5,
std::cout << std::endl;
}
Why I can assign to begin()
but it does nothing on the elements?
c++ vector
New contributor
2
Why would you expect it to change anything in the vector? All you modify is an iterator
– UnholySheep
Mar 29 at 19:33
7
It compiles if you include the necessary header files - I've added them. Why people think that including these in their question is optional, I will never know.
– Neil Butterworth
Mar 29 at 19:35
@RSahu: Here is the output from Ideone: ideone.com/19AVFF
– Syfu_H
Mar 29 at 19:35
1
Why would anyone want to close a clear question that touches a non trivial C++ subject?
– curiousguy
Mar 30 at 2:01
add a comment |
I've a bit understanding about lvalue and rvalues. So as I know we cannot assign to an rvalue but non-const lvalue is ok.
#include <iostream>
#include <vector>
int main(){
std::vector<int> v{ 1, 2, 3, 4, 5 };
v.begin() = v.end() - 2;
std::cout << *v.begin() << std::endl; // 1
for (auto const& e : v)
std::cout << e << ", ";// 1, 2, 3, 4, 5,
std::cout << std::endl;
}
Why I can assign to begin()
but it does nothing on the elements?
c++ vector
New contributor
I've a bit understanding about lvalue and rvalues. So as I know we cannot assign to an rvalue but non-const lvalue is ok.
#include <iostream>
#include <vector>
int main(){
std::vector<int> v{ 1, 2, 3, 4, 5 };
v.begin() = v.end() - 2;
std::cout << *v.begin() << std::endl; // 1
for (auto const& e : v)
std::cout << e << ", ";// 1, 2, 3, 4, 5,
std::cout << std::endl;
}
Why I can assign to begin()
but it does nothing on the elements?
c++ vector
c++ vector
New contributor
New contributor
edited Mar 29 at 19:34
Neil Butterworth
27.3k54681
27.3k54681
New contributor
asked Mar 29 at 19:29
Syfu_HSyfu_H
744
744
New contributor
New contributor
2
Why would you expect it to change anything in the vector? All you modify is an iterator
– UnholySheep
Mar 29 at 19:33
7
It compiles if you include the necessary header files - I've added them. Why people think that including these in their question is optional, I will never know.
– Neil Butterworth
Mar 29 at 19:35
@RSahu: Here is the output from Ideone: ideone.com/19AVFF
– Syfu_H
Mar 29 at 19:35
1
Why would anyone want to close a clear question that touches a non trivial C++ subject?
– curiousguy
Mar 30 at 2:01
add a comment |
2
Why would you expect it to change anything in the vector? All you modify is an iterator
– UnholySheep
Mar 29 at 19:33
7
It compiles if you include the necessary header files - I've added them. Why people think that including these in their question is optional, I will never know.
– Neil Butterworth
Mar 29 at 19:35
@RSahu: Here is the output from Ideone: ideone.com/19AVFF
– Syfu_H
Mar 29 at 19:35
1
Why would anyone want to close a clear question that touches a non trivial C++ subject?
– curiousguy
Mar 30 at 2:01
2
2
Why would you expect it to change anything in the vector? All you modify is an iterator
– UnholySheep
Mar 29 at 19:33
Why would you expect it to change anything in the vector? All you modify is an iterator
– UnholySheep
Mar 29 at 19:33
7
7
It compiles if you include the necessary header files - I've added them. Why people think that including these in their question is optional, I will never know.
– Neil Butterworth
Mar 29 at 19:35
It compiles if you include the necessary header files - I've added them. Why people think that including these in their question is optional, I will never know.
– Neil Butterworth
Mar 29 at 19:35
@RSahu: Here is the output from Ideone: ideone.com/19AVFF
– Syfu_H
Mar 29 at 19:35
@RSahu: Here is the output from Ideone: ideone.com/19AVFF
– Syfu_H
Mar 29 at 19:35
1
1
Why would anyone want to close a clear question that touches a non trivial C++ subject?
– curiousguy
Mar 30 at 2:01
Why would anyone want to close a clear question that touches a non trivial C++ subject?
– curiousguy
Mar 30 at 2:01
add a comment |
3 Answers
3
active
oldest
votes
v.begin()
is an iterator. Assigning to an iterator does not assign to the value the iterator points to. In addition, because v.begin()
is a prvalue, the object that you are assigning to gets destroyed at the end of the line, without affecting v
or any of the "permanent" memory it owns.
If v.begin()
were a raw pointer, the compiler would issue an error for trying to assign to an rvalue. However, the type std::vector<T>::iterator
is often a class type, and it seems that this is the case on your implementation (with the specific set of compiler flags you are using), so assigning to v.begin()
calls the operator=
of that class type. But that doesn't change the fact that the iterator object is a temporary object, and assigning to it has no further effects.
In order to assign to the element that v.begin()
points to, you need to dereference it: *v.begin() = *(v.end() - 2)
4
What, no digression into lvalue qualified member functions?
– Yakk - Adam Nevraumont
Mar 29 at 19:52
add a comment |
What is the result of assigning to std::vector::begin()?
The result of the assignment expression (the result is discarded in your example) is the assigned value. In this case the result is same as v.end() - 2
.
Note that since begin()
returns a value, this assignment only modifies the returned temporary object. The assignment doesn't modify the vector in any way. Given that the temporary object is discarded, the assignment has no observable effects in practice.
Futhermore, this assignment may be ill-formed if the standard library has chosen to implement std::vector::iterator
as a pointer.
Why I can assign to
begin()
Because
- Iterators are assignable.
- Rvalues of class type can be assigned †.
- The iterator happens to be a class type.
but it does nothing on the elements?
Because assigning an iterator doesn't modify the element that the iterator points at. Instead, the assignment changes what object the iterator is pointing at.
So as I know we cannot assign to an rvalue
This is not correct in general. In particular, it is not true for class types †.
† Unless the assignment operator of the class has lvalue-ref-qualifier (and has no rvalue-ref-qualified overload), which is unconventional.
How is a ref qualifier on an assignment operator "unconventional"? I'm unaware of any decent coding convention that fails to recommend it.
– Yakk - Adam Nevraumont
Mar 29 at 19:53
@Yakk-AdamNevraumont It's not conventional for the standard library as far as I know. Can you name a class from standard library that uses it? I don't recall any, but that doesn't of course mean that they don't exist.
– eerorika
Mar 29 at 19:56
@eerorika While looking into another question, I've just foundstd::optional::value
that has ref qualifiers. I don't remember seeing them anywhere else in the standard library though.
– François Andrieux
Mar 29 at 20:17
add a comment |
Sometimes code explains things better than words. Your code is equivalent to this:
std::vector<int> v{ 1, 2, 3, 4, 5 };
{
auto temp = v.begin();
temp = v.end() - 2;
}
std::cout << *v.begin() << std::endl; // 1
for (auto const& e : v)
std::cout << e << ", ";// 1, 2, 3, 4, 5,
std::cout << std::endl;
In other words, v.begin() = v.end() - 2
has no observable effect. It's just an assignment to a temporary.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Syfu_H is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55424362%2fwhat-is-the-result-of-assigning-to-stdvectortbegin%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
v.begin()
is an iterator. Assigning to an iterator does not assign to the value the iterator points to. In addition, because v.begin()
is a prvalue, the object that you are assigning to gets destroyed at the end of the line, without affecting v
or any of the "permanent" memory it owns.
If v.begin()
were a raw pointer, the compiler would issue an error for trying to assign to an rvalue. However, the type std::vector<T>::iterator
is often a class type, and it seems that this is the case on your implementation (with the specific set of compiler flags you are using), so assigning to v.begin()
calls the operator=
of that class type. But that doesn't change the fact that the iterator object is a temporary object, and assigning to it has no further effects.
In order to assign to the element that v.begin()
points to, you need to dereference it: *v.begin() = *(v.end() - 2)
4
What, no digression into lvalue qualified member functions?
– Yakk - Adam Nevraumont
Mar 29 at 19:52
add a comment |
v.begin()
is an iterator. Assigning to an iterator does not assign to the value the iterator points to. In addition, because v.begin()
is a prvalue, the object that you are assigning to gets destroyed at the end of the line, without affecting v
or any of the "permanent" memory it owns.
If v.begin()
were a raw pointer, the compiler would issue an error for trying to assign to an rvalue. However, the type std::vector<T>::iterator
is often a class type, and it seems that this is the case on your implementation (with the specific set of compiler flags you are using), so assigning to v.begin()
calls the operator=
of that class type. But that doesn't change the fact that the iterator object is a temporary object, and assigning to it has no further effects.
In order to assign to the element that v.begin()
points to, you need to dereference it: *v.begin() = *(v.end() - 2)
4
What, no digression into lvalue qualified member functions?
– Yakk - Adam Nevraumont
Mar 29 at 19:52
add a comment |
v.begin()
is an iterator. Assigning to an iterator does not assign to the value the iterator points to. In addition, because v.begin()
is a prvalue, the object that you are assigning to gets destroyed at the end of the line, without affecting v
or any of the "permanent" memory it owns.
If v.begin()
were a raw pointer, the compiler would issue an error for trying to assign to an rvalue. However, the type std::vector<T>::iterator
is often a class type, and it seems that this is the case on your implementation (with the specific set of compiler flags you are using), so assigning to v.begin()
calls the operator=
of that class type. But that doesn't change the fact that the iterator object is a temporary object, and assigning to it has no further effects.
In order to assign to the element that v.begin()
points to, you need to dereference it: *v.begin() = *(v.end() - 2)
v.begin()
is an iterator. Assigning to an iterator does not assign to the value the iterator points to. In addition, because v.begin()
is a prvalue, the object that you are assigning to gets destroyed at the end of the line, without affecting v
or any of the "permanent" memory it owns.
If v.begin()
were a raw pointer, the compiler would issue an error for trying to assign to an rvalue. However, the type std::vector<T>::iterator
is often a class type, and it seems that this is the case on your implementation (with the specific set of compiler flags you are using), so assigning to v.begin()
calls the operator=
of that class type. But that doesn't change the fact that the iterator object is a temporary object, and assigning to it has no further effects.
In order to assign to the element that v.begin()
points to, you need to dereference it: *v.begin() = *(v.end() - 2)
answered Mar 29 at 19:36
BrianBrian
66.4k798190
66.4k798190
4
What, no digression into lvalue qualified member functions?
– Yakk - Adam Nevraumont
Mar 29 at 19:52
add a comment |
4
What, no digression into lvalue qualified member functions?
– Yakk - Adam Nevraumont
Mar 29 at 19:52
4
4
What, no digression into lvalue qualified member functions?
– Yakk - Adam Nevraumont
Mar 29 at 19:52
What, no digression into lvalue qualified member functions?
– Yakk - Adam Nevraumont
Mar 29 at 19:52
add a comment |
What is the result of assigning to std::vector::begin()?
The result of the assignment expression (the result is discarded in your example) is the assigned value. In this case the result is same as v.end() - 2
.
Note that since begin()
returns a value, this assignment only modifies the returned temporary object. The assignment doesn't modify the vector in any way. Given that the temporary object is discarded, the assignment has no observable effects in practice.
Futhermore, this assignment may be ill-formed if the standard library has chosen to implement std::vector::iterator
as a pointer.
Why I can assign to
begin()
Because
- Iterators are assignable.
- Rvalues of class type can be assigned †.
- The iterator happens to be a class type.
but it does nothing on the elements?
Because assigning an iterator doesn't modify the element that the iterator points at. Instead, the assignment changes what object the iterator is pointing at.
So as I know we cannot assign to an rvalue
This is not correct in general. In particular, it is not true for class types †.
† Unless the assignment operator of the class has lvalue-ref-qualifier (and has no rvalue-ref-qualified overload), which is unconventional.
How is a ref qualifier on an assignment operator "unconventional"? I'm unaware of any decent coding convention that fails to recommend it.
– Yakk - Adam Nevraumont
Mar 29 at 19:53
@Yakk-AdamNevraumont It's not conventional for the standard library as far as I know. Can you name a class from standard library that uses it? I don't recall any, but that doesn't of course mean that they don't exist.
– eerorika
Mar 29 at 19:56
@eerorika While looking into another question, I've just foundstd::optional::value
that has ref qualifiers. I don't remember seeing them anywhere else in the standard library though.
– François Andrieux
Mar 29 at 20:17
add a comment |
What is the result of assigning to std::vector::begin()?
The result of the assignment expression (the result is discarded in your example) is the assigned value. In this case the result is same as v.end() - 2
.
Note that since begin()
returns a value, this assignment only modifies the returned temporary object. The assignment doesn't modify the vector in any way. Given that the temporary object is discarded, the assignment has no observable effects in practice.
Futhermore, this assignment may be ill-formed if the standard library has chosen to implement std::vector::iterator
as a pointer.
Why I can assign to
begin()
Because
- Iterators are assignable.
- Rvalues of class type can be assigned †.
- The iterator happens to be a class type.
but it does nothing on the elements?
Because assigning an iterator doesn't modify the element that the iterator points at. Instead, the assignment changes what object the iterator is pointing at.
So as I know we cannot assign to an rvalue
This is not correct in general. In particular, it is not true for class types †.
† Unless the assignment operator of the class has lvalue-ref-qualifier (and has no rvalue-ref-qualified overload), which is unconventional.
How is a ref qualifier on an assignment operator "unconventional"? I'm unaware of any decent coding convention that fails to recommend it.
– Yakk - Adam Nevraumont
Mar 29 at 19:53
@Yakk-AdamNevraumont It's not conventional for the standard library as far as I know. Can you name a class from standard library that uses it? I don't recall any, but that doesn't of course mean that they don't exist.
– eerorika
Mar 29 at 19:56
@eerorika While looking into another question, I've just foundstd::optional::value
that has ref qualifiers. I don't remember seeing them anywhere else in the standard library though.
– François Andrieux
Mar 29 at 20:17
add a comment |
What is the result of assigning to std::vector::begin()?
The result of the assignment expression (the result is discarded in your example) is the assigned value. In this case the result is same as v.end() - 2
.
Note that since begin()
returns a value, this assignment only modifies the returned temporary object. The assignment doesn't modify the vector in any way. Given that the temporary object is discarded, the assignment has no observable effects in practice.
Futhermore, this assignment may be ill-formed if the standard library has chosen to implement std::vector::iterator
as a pointer.
Why I can assign to
begin()
Because
- Iterators are assignable.
- Rvalues of class type can be assigned †.
- The iterator happens to be a class type.
but it does nothing on the elements?
Because assigning an iterator doesn't modify the element that the iterator points at. Instead, the assignment changes what object the iterator is pointing at.
So as I know we cannot assign to an rvalue
This is not correct in general. In particular, it is not true for class types †.
† Unless the assignment operator of the class has lvalue-ref-qualifier (and has no rvalue-ref-qualified overload), which is unconventional.
What is the result of assigning to std::vector::begin()?
The result of the assignment expression (the result is discarded in your example) is the assigned value. In this case the result is same as v.end() - 2
.
Note that since begin()
returns a value, this assignment only modifies the returned temporary object. The assignment doesn't modify the vector in any way. Given that the temporary object is discarded, the assignment has no observable effects in practice.
Futhermore, this assignment may be ill-formed if the standard library has chosen to implement std::vector::iterator
as a pointer.
Why I can assign to
begin()
Because
- Iterators are assignable.
- Rvalues of class type can be assigned †.
- The iterator happens to be a class type.
but it does nothing on the elements?
Because assigning an iterator doesn't modify the element that the iterator points at. Instead, the assignment changes what object the iterator is pointing at.
So as I know we cannot assign to an rvalue
This is not correct in general. In particular, it is not true for class types †.
† Unless the assignment operator of the class has lvalue-ref-qualifier (and has no rvalue-ref-qualified overload), which is unconventional.
edited Mar 29 at 21:58
answered Mar 29 at 19:34
eerorikaeerorika
89.2k664136
89.2k664136
How is a ref qualifier on an assignment operator "unconventional"? I'm unaware of any decent coding convention that fails to recommend it.
– Yakk - Adam Nevraumont
Mar 29 at 19:53
@Yakk-AdamNevraumont It's not conventional for the standard library as far as I know. Can you name a class from standard library that uses it? I don't recall any, but that doesn't of course mean that they don't exist.
– eerorika
Mar 29 at 19:56
@eerorika While looking into another question, I've just foundstd::optional::value
that has ref qualifiers. I don't remember seeing them anywhere else in the standard library though.
– François Andrieux
Mar 29 at 20:17
add a comment |
How is a ref qualifier on an assignment operator "unconventional"? I'm unaware of any decent coding convention that fails to recommend it.
– Yakk - Adam Nevraumont
Mar 29 at 19:53
@Yakk-AdamNevraumont It's not conventional for the standard library as far as I know. Can you name a class from standard library that uses it? I don't recall any, but that doesn't of course mean that they don't exist.
– eerorika
Mar 29 at 19:56
@eerorika While looking into another question, I've just foundstd::optional::value
that has ref qualifiers. I don't remember seeing them anywhere else in the standard library though.
– François Andrieux
Mar 29 at 20:17
How is a ref qualifier on an assignment operator "unconventional"? I'm unaware of any decent coding convention that fails to recommend it.
– Yakk - Adam Nevraumont
Mar 29 at 19:53
How is a ref qualifier on an assignment operator "unconventional"? I'm unaware of any decent coding convention that fails to recommend it.
– Yakk - Adam Nevraumont
Mar 29 at 19:53
@Yakk-AdamNevraumont It's not conventional for the standard library as far as I know. Can you name a class from standard library that uses it? I don't recall any, but that doesn't of course mean that they don't exist.
– eerorika
Mar 29 at 19:56
@Yakk-AdamNevraumont It's not conventional for the standard library as far as I know. Can you name a class from standard library that uses it? I don't recall any, but that doesn't of course mean that they don't exist.
– eerorika
Mar 29 at 19:56
@eerorika While looking into another question, I've just found
std::optional::value
that has ref qualifiers. I don't remember seeing them anywhere else in the standard library though.– François Andrieux
Mar 29 at 20:17
@eerorika While looking into another question, I've just found
std::optional::value
that has ref qualifiers. I don't remember seeing them anywhere else in the standard library though.– François Andrieux
Mar 29 at 20:17
add a comment |
Sometimes code explains things better than words. Your code is equivalent to this:
std::vector<int> v{ 1, 2, 3, 4, 5 };
{
auto temp = v.begin();
temp = v.end() - 2;
}
std::cout << *v.begin() << std::endl; // 1
for (auto const& e : v)
std::cout << e << ", ";// 1, 2, 3, 4, 5,
std::cout << std::endl;
In other words, v.begin() = v.end() - 2
has no observable effect. It's just an assignment to a temporary.
add a comment |
Sometimes code explains things better than words. Your code is equivalent to this:
std::vector<int> v{ 1, 2, 3, 4, 5 };
{
auto temp = v.begin();
temp = v.end() - 2;
}
std::cout << *v.begin() << std::endl; // 1
for (auto const& e : v)
std::cout << e << ", ";// 1, 2, 3, 4, 5,
std::cout << std::endl;
In other words, v.begin() = v.end() - 2
has no observable effect. It's just an assignment to a temporary.
add a comment |
Sometimes code explains things better than words. Your code is equivalent to this:
std::vector<int> v{ 1, 2, 3, 4, 5 };
{
auto temp = v.begin();
temp = v.end() - 2;
}
std::cout << *v.begin() << std::endl; // 1
for (auto const& e : v)
std::cout << e << ", ";// 1, 2, 3, 4, 5,
std::cout << std::endl;
In other words, v.begin() = v.end() - 2
has no observable effect. It's just an assignment to a temporary.
Sometimes code explains things better than words. Your code is equivalent to this:
std::vector<int> v{ 1, 2, 3, 4, 5 };
{
auto temp = v.begin();
temp = v.end() - 2;
}
std::cout << *v.begin() << std::endl; // 1
for (auto const& e : v)
std::cout << e << ", ";// 1, 2, 3, 4, 5,
std::cout << std::endl;
In other words, v.begin() = v.end() - 2
has no observable effect. It's just an assignment to a temporary.
answered Mar 29 at 20:16
Nikos C.Nikos C.
34k53967
34k53967
add a comment |
add a comment |
Syfu_H is a new contributor. Be nice, and check out our Code of Conduct.
Syfu_H is a new contributor. Be nice, and check out our Code of Conduct.
Syfu_H is a new contributor. Be nice, and check out our Code of Conduct.
Syfu_H is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55424362%2fwhat-is-the-result-of-assigning-to-stdvectortbegin%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
Why would you expect it to change anything in the vector? All you modify is an iterator
– UnholySheep
Mar 29 at 19:33
7
It compiles if you include the necessary header files - I've added them. Why people think that including these in their question is optional, I will never know.
– Neil Butterworth
Mar 29 at 19:35
@RSahu: Here is the output from Ideone: ideone.com/19AVFF
– Syfu_H
Mar 29 at 19:35
1
Why would anyone want to close a clear question that touches a non trivial C++ subject?
– curiousguy
Mar 30 at 2:01