Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7030517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:40:51+00:00 2026-05-28T00:40:51+00:00

While iterating through a std::map or std::vector or any container which has iterator in

  • 0

While iterating through a std::map or std::vector or any container which has iterator in it, is checked against the variable.end() and not something like container<>::end. For example,

map<int, int> var;
for(map<int, int>::iterator it = var.begin(); it != var.end(); it++)
...                                           ^^^^^^^^^^^^^^^

Can’t above highlighted part be something like:

it != map<int,int>::end

which is similar to static member string::npos. What can be the reason behind the design decision for providing .end() on per variable bases and not on the per type of container bases ? (i.e. map<int,int>::end and map<int,double>::end would be different; but for every map<int,int> variable, the ::end will be similar.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T00:40:52+00:00Added an answer on May 28, 2026 at 12:40 am

    Iterators are for iterating, moving forward and backward. They need to provide increment and decrement (bidirectional iterators) operations. When you decrement an end() iterator, you get to the last item in the container. This allows iterating backwards.

    As to your suggestion. Implementing this would mean that each iterator carries the end iterator with it, and compares equal to the static end iterator when it is equal to the real end iterator it is storing. There would actually be no point to make all the static end iterators different types, because that “iterator” cannot be used for anything other than that anyway.

    A design like that would simply be more cumbersome to implement and more wasteful to use. If each iterator has to know the end of its container, then to designate an arbitrary range, you’d have to add two potentially unused iterators to the end in the mix.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Duplicate Modifying A Collection While Iterating Through It Has anyone a nice pattern to
Possible Duplicate: for vs foreach vs while which is faster for iterating through arrays
Possible Duplicate: Can you remove elements from a std::list while iterating through it? I
Possible Duplicate: Can you remove elements from a std::list while iterating through it? I
What's a better way to traverse an array while iterating through another array? For
What is the proper way to remove elements from a C++ vector while iterating
I have an associative array and while iterating through this array, using foreach loop.
I am having an issue removing elements of a list while iterating through the
While iterating through an object containing data I'm checking if the url of image
How do I access the index while iterating over a sequence with a for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.