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 7728905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:50:06+00:00 2026-06-01T05:50:06+00:00

Why does the Standard define end() as one past the end, instead of at

  • 0

Why does the Standard define end() as one past the end, instead of at the actual end?

  • 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-06-01T05:50:08+00:00Added an answer on June 1, 2026 at 5:50 am

    The best argument easily is the one made by Dijkstra himself:

    • You want the size of the range to be a simple difference end − begin;

    • including the lower bound is more “natural” when sequences degenerate to empty ones, and also because the alternative (excluding the lower bound) would require the existence of a “one-before-the-beginning” sentinel value.

    You still need to justify why you start counting at zero rather than one, but that wasn’t part of your question.

    The wisdom behind the [begin, end) convention pays off time and again when you have any sort of algorithm that deals with multiple nested or iterated calls to range-based constructions, which chain naturally. By contrast, using a doubly-closed range would incur off-by-ones and extremely unpleasant and noisy code. For example, consider a partition [n0, n1)[n1, n2)[n2,n3). Another example is the standard iteration loop for (it = begin; it != end; ++it), which runs end - begin times. The corresponding code would be much less readable if both ends were inclusive – and imagine how you’d handle empty ranges.

    Finally, we can also make a nice argument why counting should start at zero: With the half-open convention for ranges that we just established, if you are given a range of N elements (say to enumerate the members of an array), then 0 is the natural “beginning” so that you can write the range as [0, N), without any awkward offsets or corrections.

    In a nutshell: the fact that we don’t see the number 1 everywhere in range-based algorithms is a direct consequence of, and motivation for, the [begin, end) convention.

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

Sidebar

Related Questions

Does the C++ Standard Library define this function, or do I have to resort
Does the standard define precisely what I can do with an object once it
Does the standard define what happens with this code? #include <iostream> template <typename Func>
What does standard specify about indexing sequence with Attr objects inside NamedNodeMap object? I
Does the standard guarantee that order of equal elements will not change (eh, forgot
Does the C standard support something similar to __func__ for the function arguments' names?
Does anyone know a standard way to keep alive the http session as long
The standard logging code does not seem to work instantiating a logger with the
Does a jQuery plug-in exist with standard lightbox functionality? In the lightbox window I'd
Does anyone know of any best practices or 'standard' techniques for implementing authentication between

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.