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

[range.range] LWG 3361: Misleading description of safe_range #3564

Closed
JohelEGP opened this issue Dec 16, 2019 · 4 comments
Closed

[range.range] LWG 3361: Misleading description of safe_range #3564

JohelEGP opened this issue Dec 16, 2019 · 4 comments

Comments

@JohelEGP
Copy link
Contributor

From http://eel.is/c++draft/range.range#itemdecl:2:

template<class T>
 concept safe_­range =
   range<T> &&
     (is_lvalue_reference_v<T> || enable_safe_range<remove_cvref_t<T>>);

Given an expression E such that decltype((E)) is T, T models safe_­range only if the validity of iterators obtained from the object denoted by E is not tied to the lifetime of that object.

[ Note: Since the validity of iterators is not tied to the lifetime of an object whose type models safe_­range, a function can accept arguments of such a type by value and return iterators obtained from it without danger of dangling. — end note ]

Given std::vector<int> x{1, 2, 3};, if E is x, its type std::vector<int>& models safe_range, but the validity of the iterators obtained from the object it denotes are tied to its lifetime.

@JohelEGP
Copy link
Contributor Author

This is actually normative. As such, std::vector<int>& can't model safe_range because the iterators of x are tied to the lifetime of the object it denotes. The intention is to actually allow such a case, given its use throughout [range.subrange] and in [range.dangling]#2.

@CaseyCarter
Copy link
Contributor

Ugh, this is a train wreck. Please file an LWG issue?

@JohelEGP
Copy link
Contributor Author

Sure. Will post the issue number here when it is issued.

@JohelEGP
Copy link
Contributor Author

This is now http://wg21.link/LWG3361.

@jensmaurer jensmaurer changed the title [range.range] Misleading description of safe_range [range.range] LWG 3361: Misleading description of safe_range Dec 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants