Title
ranges::empty has no semantic requirements for forward_ranges
Status
new
Section
[range.prim.empty]
Submitter
Hewill Kang

Created on 2024-03-30.00:00:00 last changed 1 month ago

Messages

Date: 2024-03-30.00:00:00

This is a small part of issues raised by already-closed P3156.

Currently, ranges::empty ([range.prim.empty]) is always a valid expression when applied to forward_ranges, because even if it does not have .empty() or .size() we can always check whether it is empty by comparing its begin() and end(), which is reflected in the standard preference to use it to check whether a certain forward_range is empty, such as in the Effects of split_view::find-next() ([range.split.view]) and cartesian_product_view::end() ([range.cartesian.view]).

In addition, MSVC-STL also uses ranges::empty in the implementation of ranges::contains_subrange for the check.

However, unlike ranges::size, which has a sized_range concept to ensure semantics, ranges::empty has no corresponding one. This makes it lack of time complexity guarantees and semantics for the meaning of the returned value when using the bullets (2.2) and (2.3) of [range.prim.empty] to check emptiness.

Perhaps we need to add semantic requirements for ranges::empty, but this seems inconsistent with the current wording as no other CPOs have.

Alternatively, maybe we could move bullets targeting forward_ranges to the very beginning so that ranges::empty always has correct semantics with bool(ranges::begin(t) == ranges::end(t)) when applied to forward_ranges.

History
Date User Action Args
2024-03-30 00:00:00admincreate