Closed ericniebler closed 5 years ago
It it kosher to construct a subrange for which end is not reachable from begin?
Technically, yes it is. The resulting subrange
wouldn't be in the domain of Range
, however, since [range.range]/3.1 requires that "[ranges::begin(E), ranges::end(E))
denotes a range ([iterator.requirements.general])".
This seems like the sort of weirdness we should forbid.
PR for your perusal.
This issue is now LWG 3179.
Does this mean subrange(iota_view::iterator(0u), unreachable_sentinel)
(or subrange(iota(0u))
) is disallowed?
No, those are fine.
"Being a valid range" imposes the reachability condition, but [iota_view::iterator(0u), unreachable_sentinel)
does not satisfy the reachability condition. Thus, after this PR is applied, subrange(iota_view::iterator(0u), unreachable_sentinel)
becomes UB.
Or, I may be misunderstanding the validity of ranges / unreachable_sentinel
.
We have a known issue regarding the definition of valid range in terms of reachability.
Ah, ok, understood. Thanks for the reply!
Is it kosher to construct a subrange for which end is not reachable from begin? Say, if begin is reachable from end instead? And
size()
returns a negative number?Probably not. If that is the case, we should require that [begin,end) denotes a valid range.
Proposed Resolution
Change [range.subrange.ctor] as follows: