Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

subrange: must end be reachable from begin? #597

Closed
ericniebler opened this issue Dec 19, 2018 · 7 comments
Closed

subrange: must end be reachable from begin? #597

ericniebler opened this issue Dec 19, 2018 · 7 comments

Comments

@ericniebler
Copy link
Owner

ericniebler commented Dec 19, 2018

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:

 constexpr subrange(I i, S s) requires (!StoreSize);

+-?- Expects: [i, s) is a valid range.

 -1- Effects: Initializes begin_ with i and end_ with s.

 constexpr subrange(I i, S s, iter_difference_t<I> n)
   requires (K == subrange_kind::sized);
 
 -2- Expects: 
+    [i, s) is a valid range, and
     n == ranges::distance(i, s).
@ericniebler ericniebler changed the title subrange: must end be reac subrange: must end be reachable from begin? Dec 19, 2018
@CaseyCarter
Copy link
Collaborator

CaseyCarter commented Dec 19, 2018

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.

@CaseyCarter
Copy link
Collaborator

This issue is now LWG 3179.

@morinmorin
Copy link

Does this mean subrange(iota_view::iterator(0u), unreachable_sentinel) (or subrange(iota(0u))) is disallowed?

@ericniebler
Copy link
Owner Author

No, those are fine.

@morinmorin
Copy link

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

@ericniebler
Copy link
Owner Author

We have a known issue regarding the definition of valid range in terms of reachability.

@morinmorin
Copy link

Ah, ok, understood. Thanks for the reply!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants