What is half open range and off the end value

后端 未结 3 763
隐瞒了意图╮
隐瞒了意图╮ 2020-12-01 16:01

What do these terminologies mean in C++?

1. off the end value

2. half open range - [begin, off_the_end)

3条回答
  •  离开以前
    2020-12-01 16:40

    These aren't C++ specific terms, they are general maths 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)

提交回复
热议问题