Why are Standard iterator ranges [begin, end) inst

2019-01-01 14:51发布

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

7条回答
谁念西风独自凉
2楼-- · 2019-01-01 15:16

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

Because:

  1. It avoids special handling for empty ranges. For empty ranges, begin() is equal to end() &
  2. It makes the end criterion simple for loops that iterate over the elements: The loops simply continue as long as end() is not reached.
查看更多
登录 后发表回答