What is the result of assigning to std::vector::begin()? The Next CEO of Stack OverflowWhat are the differences between a pointer variable and a reference variable in C++?What does the explicit keyword mean?Concatenating two std::vectorsHow to find out if an item is present in a std::vector?Why is “using namespace std” considered bad practice?What is the “-->” operator in C++?What is the easiest way to initialize a std::vector with hardcoded elements?What is The Rule of Three?What are the basic rules and idioms for operator overloading?Why are std::begin and std::end “not memory safe”?

Is there a way to save my career from absolute disaster?

Why didn't Khan get resurrected in the Genesis Explosion?

How to make a variable always equal to the result of some calculations?

What can we do to stop prior company from asking us questions?

How do we know the LHC results are robust?

How does the mv command work with external drives?

What is ( CFMCC ) on ILS approach chart?

Between two walls

Should I tutor a student who I know has cheated on their homework?

How do scammers retract money, while you can’t?

What happens if you roll doubles 3 times then land on "Go to jail?"

What is the result of assigning to std::vector<T>::begin()?

How to count occurrences of text in a file?

What was the first Unix version to run on a microcomputer?

Return the Closest Prime Number

How did people program for Consoles with multiple CPUs?

What does convergence in distribution "in the Gromov–Hausdorff" sense mean?

How should I support this large drywall patch?

How to transpose the 1st and -1th levels of arbitrarily nested array?

Why is the US ranked as #45 in Press Freedom ratings, despite its extremely permissive free speech laws?

Won the lottery - how do I keep the money?

Why do we use the plural of movies in this phrase "We went to the movies last night."?

Rotate a column

Is micro rebar a better way to reinforce concrete than rebar?



What is the result of assigning to std::vector::begin()?



The Next CEO of Stack OverflowWhat are the differences between a pointer variable and a reference variable in C++?What does the explicit keyword mean?Concatenating two std::vectorsHow to find out if an item is present in a std::vector?Why is “using namespace std” considered bad practice?What is the “-->” operator in C++?What is the easiest way to initialize a std::vector with hardcoded elements?What is The Rule of Three?What are the basic rules and idioms for operator overloading?Why are std::begin and std::end “not memory safe”?










6















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?










share|improve this question









New contributor




Syfu_H is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • Why would you expect it to change anything in the vector? All you modify is an iterator

    – UnholySheep
    2 hours ago






  • 4





    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
    2 hours ago












  • @RSahu: Here is the output from Ideone: ideone.com/19AVFF

    – Syfu_H
    2 hours ago















6















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?










share|improve this question









New contributor




Syfu_H is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • Why would you expect it to change anything in the vector? All you modify is an iterator

    – UnholySheep
    2 hours ago






  • 4





    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
    2 hours ago












  • @RSahu: Here is the output from Ideone: ideone.com/19AVFF

    – Syfu_H
    2 hours ago













6












6








6


5






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?










share|improve this question









New contributor




Syfu_H is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












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






share|improve this question









New contributor




Syfu_H is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Syfu_H is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 2 hours ago









Neil Butterworth

27.2k54681




27.2k54681






New contributor




Syfu_H is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 2 hours ago









Syfu_HSyfu_H

493




493




New contributor




Syfu_H is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Syfu_H is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Syfu_H is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • Why would you expect it to change anything in the vector? All you modify is an iterator

    – UnholySheep
    2 hours ago






  • 4





    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
    2 hours ago












  • @RSahu: Here is the output from Ideone: ideone.com/19AVFF

    – Syfu_H
    2 hours ago

















  • Why would you expect it to change anything in the vector? All you modify is an iterator

    – UnholySheep
    2 hours ago






  • 4





    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
    2 hours ago












  • @RSahu: Here is the output from Ideone: ideone.com/19AVFF

    – Syfu_H
    2 hours ago
















Why would you expect it to change anything in the vector? All you modify is an iterator

– UnholySheep
2 hours ago





Why would you expect it to change anything in the vector? All you modify is an iterator

– UnholySheep
2 hours ago




4




4





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
2 hours ago






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
2 hours ago














@RSahu: Here is the output from Ideone: ideone.com/19AVFF

– Syfu_H
2 hours ago





@RSahu: Here is the output from Ideone: ideone.com/19AVFF

– Syfu_H
2 hours ago












3 Answers
3






active

oldest

votes


















11














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)






share|improve this answer


















  • 1





    What, no digression into lvalue qualified member functions?

    – Yakk - Adam Nevraumont
    2 hours ago


















5















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



  1. Iterators are assignable.

  2. Rvalues of class type can be assigned .

  3. 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.






share|improve this answer

























  • 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
    2 hours ago











  • @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
    2 hours ago












  • @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
    1 hour ago












  • What happened to produce "cdagger typoan"?

    – genpfault
    21 mins ago












  • @genpfault :D I usually google for dagger typo so that I can copy paste †. I don't know how I managed to get it into the answer.

    – eerorika
    10 mins ago


















1














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.






share|improve this answer























    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.









    draft saved

    draft discarded


















    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









    11














    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)






    share|improve this answer


















    • 1





      What, no digression into lvalue qualified member functions?

      – Yakk - Adam Nevraumont
      2 hours ago















    11














    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)






    share|improve this answer


















    • 1





      What, no digression into lvalue qualified member functions?

      – Yakk - Adam Nevraumont
      2 hours ago













    11












    11








    11







    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)






    share|improve this answer













    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)







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered 2 hours ago









    BrianBrian

    66.2k798189




    66.2k798189







    • 1





      What, no digression into lvalue qualified member functions?

      – Yakk - Adam Nevraumont
      2 hours ago












    • 1





      What, no digression into lvalue qualified member functions?

      – Yakk - Adam Nevraumont
      2 hours ago







    1




    1





    What, no digression into lvalue qualified member functions?

    – Yakk - Adam Nevraumont
    2 hours ago





    What, no digression into lvalue qualified member functions?

    – Yakk - Adam Nevraumont
    2 hours ago













    5















    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



    1. Iterators are assignable.

    2. Rvalues of class type can be assigned .

    3. 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.






    share|improve this answer

























    • 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
      2 hours ago











    • @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
      2 hours ago












    • @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
      1 hour ago












    • What happened to produce "cdagger typoan"?

      – genpfault
      21 mins ago












    • @genpfault :D I usually google for dagger typo so that I can copy paste †. I don't know how I managed to get it into the answer.

      – eerorika
      10 mins ago















    5















    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



    1. Iterators are assignable.

    2. Rvalues of class type can be assigned .

    3. 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.






    share|improve this answer

























    • 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
      2 hours ago











    • @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
      2 hours ago












    • @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
      1 hour ago












    • What happened to produce "cdagger typoan"?

      – genpfault
      21 mins ago












    • @genpfault :D I usually google for dagger typo so that I can copy paste †. I don't know how I managed to get it into the answer.

      – eerorika
      10 mins ago













    5












    5








    5








    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



    1. Iterators are assignable.

    2. Rvalues of class type can be assigned .

    3. 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.






    share|improve this answer
















    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



    1. Iterators are assignable.

    2. Rvalues of class type can be assigned .

    3. 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.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited 10 mins ago

























    answered 2 hours ago









    eerorikaeerorika

    88.2k663134




    88.2k663134












    • 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
      2 hours ago











    • @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
      2 hours ago












    • @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
      1 hour ago












    • What happened to produce "cdagger typoan"?

      – genpfault
      21 mins ago












    • @genpfault :D I usually google for dagger typo so that I can copy paste †. I don't know how I managed to get it into the answer.

      – eerorika
      10 mins ago

















    • 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
      2 hours ago











    • @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
      2 hours ago












    • @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
      1 hour ago












    • What happened to produce "cdagger typoan"?

      – genpfault
      21 mins ago












    • @genpfault :D I usually google for dagger typo so that I can copy paste †. I don't know how I managed to get it into the answer.

      – eerorika
      10 mins ago
















    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
    2 hours ago





    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
    2 hours ago













    @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
    2 hours ago






    @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
    2 hours ago














    @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
    1 hour ago






    @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
    1 hour ago














    What happened to produce "cdagger typoan"?

    – genpfault
    21 mins ago






    What happened to produce "cdagger typoan"?

    – genpfault
    21 mins ago














    @genpfault :D I usually google for dagger typo so that I can copy paste †. I don't know how I managed to get it into the answer.

    – eerorika
    10 mins ago





    @genpfault :D I usually google for dagger typo so that I can copy paste †. I don't know how I managed to get it into the answer.

    – eerorika
    10 mins ago











    1














    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.






    share|improve this answer



























      1














      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.






      share|improve this answer

























        1












        1








        1







        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.






        share|improve this answer













        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.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 1 hour ago









        Nikos C.Nikos C.

        33.8k53967




        33.8k53967




















            Syfu_H is a new contributor. Be nice, and check out our Code of Conduct.









            draft saved

            draft discarded


















            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Oświęcim Innehåll Historia | Källor | Externa länkar | Navigeringsmeny50°2′18″N 19°13′17″Ö / 50.03833°N 19.22139°Ö / 50.03833; 19.2213950°2′18″N 19°13′17″Ö / 50.03833°N 19.22139°Ö / 50.03833; 19.221393089658Nordisk familjebok, AuschwitzInsidan tro och existensJewish Community i OświęcimAuschwitz Jewish Center: MuseumAuschwitz Jewish Center

            Valle di Casies Indice Geografia fisica | Origini del nome | Storia | Società | Amministrazione | Sport | Note | Bibliografia | Voci correlate | Altri progetti | Collegamenti esterni | Menu di navigazione46°46′N 12°11′E / 46.766667°N 12.183333°E46.766667; 12.183333 (Valle di Casies)46°46′N 12°11′E / 46.766667°N 12.183333°E46.766667; 12.183333 (Valle di Casies)Sito istituzionaleAstat Censimento della popolazione 2011 - Determinazione della consistenza dei tre gruppi linguistici della Provincia Autonoma di Bolzano-Alto Adige - giugno 2012Numeri e fattiValle di CasiesDato IstatTabella dei gradi/giorno dei Comuni italiani raggruppati per Regione e Provincia26 agosto 1993, n. 412Heraldry of the World: GsiesStatistiche I.StatValCasies.comWikimedia CommonsWikimedia CommonsValle di CasiesSito ufficialeValle di CasiesMM14870458910042978-6

            Typsetting diagram chases (with TikZ?) Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)How to define the default vertical distance between nodes?Draw edge on arcNumerical conditional within tikz keys?TikZ: Drawing an arc from an intersection to an intersectionDrawing rectilinear curves in Tikz, aka an Etch-a-Sketch drawingLine up nested tikz enviroments or how to get rid of themHow to place nodes in an absolute coordinate system in tikzCommutative diagram with curve connecting between nodesTikz with standalone: pinning tikz coordinates to page cmDrawing a Decision Diagram with Tikz and layout manager