Tim Elhajj

Off the Microsoft stack!

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

1 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.

Advertisement

Author: Tim Elhajj

Tim is probably walking his dog.

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

  1. Pingback: Did You Know That Slices in Go Can Take Three Indices? | Golang Project Structure

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 )

Facebook photo

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

Connecting to %s