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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:14:31+00:00 2026-05-25T19:14:31+00:00

Following on from my previous question , can we prove that the standard allows

  • 0

Following on from my previous question, can we prove that the standard allows us to pass an empty range to a standard algorithm?

Paragraph 24.1/7 defines an “empty range” as the range [i,i) (where i is valid), and i would appear to be “reachable” from itself, but I’m not sure that this qualifies as a proof.

In particular, we run into trouble when looking at the sorting functions. For example, std::sort:

Complexity: O(N log(N)) (where N == last – first) comparisons

Since log(0) is generally considered to be undefined, and I don’t know what 0*undefined is, could there be a problem here?


(Yes, ok, I’m being a bit pedantic. Of course no self-respecting stdlib implementation would cause a practical problem with an empty range passed to std::sort. But I’m wondering whether there’s a potential hole in the standard wording here.)

  • 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-25T19:14:32+00:00Added an answer on May 25, 2026 at 7:14 pm

    I don’t seem much room for question. In §24.1/6 we’re told:

    An iterator j is called reachable from an iterator i if and only if there is a finite sequence of applications of the expression ++i that makes i == j.

    and in $24.1/7:

    Range [i, j) is valid if and only if j is reachable from i.

    Since 0 is finite, [i, i) is a valid range. §24.1/7 goes on to say:

    The result of the application of functions in the library to invalid ranges is
    undefined.

    That doesn’t go quite so far as to say that a valid range guarantees defined results (reasonable, since there are other requirements, such as on the comparison function) but certainly seems to imply that a range being empty, in itself, should not lead to UB or anything like that. In particular, however, the standard makes an empty range just another valid range; there’s no real differentiation between empty and non-empty valid ranges, so what applies to a non-empty valid range applies equally well to an empty valid range.

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

Sidebar

Related Questions

Following on from a previous question in which I asked: How can I use
Following up from my previous question. Can anyone explain why the following code compiles
Following on from a previous question, ( Previous question ), I can't seem to
Following up from my previous question , why is CShell so different from C?
Following on from a previous question, for some reason when I use the following
Following on from a previous question relating to heap usage restrictions , I'm looking
Following on from a previous question , I am creating a symbolic link on
Okay, this is following on from my previous question reguarding performing a simple ajax
This problem follows on from a previous question . When I run the following
Following on from the excellent answer to my previous question: Linq Entity Framework generic

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.