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

  • Home
  • SEARCH
  • 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 6344303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:36:39+00:00 2026-05-24T20:36:39+00:00

For a std::for_each call, is it legal to have both iterators be the end

  • 0

For a std::for_each call, is it legal to have both iterators be the end iterator? For example,

std::vector<int> some_ints;
std::for_each(ints.end(), ints.end(), [&](int i) {
    std::cout << i;
});
  • 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-24T20:36:40+00:00Added an answer on May 24, 2026 at 8:36 pm

    Yes this is perfectly legal and produces an empty range. The result will be that nothing happens but the behavior is well defined.

    Here is a relevant quote from the SGI reference page on iterators and their use as ranges (Documentation)

    Most algorithms are expressed not in terms of a single iterator but in terms of a range of iterators; the notation [first, last) refers to all of the iterators from first up to, but not including, last. Note that a range may be empty, i.e. first and last may be the same iterator.

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

Sidebar

Related Questions

When using the std::for_each, class A; vector<A*> VectorOfAPointers; std::for_each(VectorOfAPointers.begin(), VectorOfAPointers.end(), std::mem_fun(&A::foo)); If we have
I've got this for loop: std::vector<itemPtr>::iterator it; for(it=items.begin(); it!=items.end(); ++it) { investigators.addToLeaderInventory(*it); } I'd
I created a lambda expression inside my std::for_each call. In it there is code
I have some code that adds to a std::vector and a std::map after creating
I have in essence the following code: typedef std::function<void ()> fnGlobalChangeEvent; typedef std::vector<fnGlobalChangeEvent> GlobalTriggers;
I have class with member functions: typedef std::function<bool (const std::string &)> InsertFunction; bool insertSourceFile(
Why does the for_each call on functor doesn't update sum::total at the end? struct
How to call class member function using std::for_each Here is what my class is.
I'm trying to use stl algorithm for_each without proliferating templates throughout my code. std::for_each
Possible Duplicate: Erasing from a std::vector while doing a for each? I'm trying to

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.