Tim Elhajj

Off the Microsoft stack!

What is meant by the term “half open range” and “off the end value” in C++?

Leave a comment

These aren’t C++ specific terms, they are general mathmatics terms.

[] and () denote whether the range is inclusive/exclusive of the endpoint:

  • [ includes the endpoint
  • ( excludes the endpoint
  • [] = ‘Closed’, includes both endpoints
  • () = ‘Open’, excludes both endpoints
  • [) and (] are both ‘half-open’, and include only one endpoint

Most C++ for-loops cover a half-open range (you include the first element: e.g for int i=0;, but exclude the final element: i < foo, not i ≤ foo)

This great answer is courtesy of jam.

Author: Tim Elhajj

Tim is probably walking his dog.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s