About C + + post-tail iterators: ++end ()

Source: Internet
Author: User

It is customary to say what ++v.begin () and--v.end () are used to, but what happens to ++v.end ()?
Come up with a simple code

vector<int> v;++v.end();

Error occurred during VS2017 debugging

The description end () iterator is not additive.
And here's what happened to me:

#include <iostream>#include <set>using namespace std;int main() {    set<char> st;    st.insert('a');    st.insert('b');    st.insert('c');    if ((st.find(0)) == st.end()) {        cout << "YES" << endl;    }    else {        cout << "NO" << endl;    }    getchar();    return 0;}

The same error occurs in debug mode.
But vs and GCC do not behave the same. In release mode vs generated program output is yes, and GCC produces no. Visible ++end () This behavior belongs to undefined behavior and needs to be avoided when considering boundary conditions.

About C + + post-tail iterators: ++end ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.