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

LWG-3847 ranges::to can still return views #3479

Merged
merged 5 commits into from
Feb 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions stl/inc/ranges
Original file line number Diff line number Diff line change
Expand Up @@ -8402,6 +8402,9 @@ namespace ranges {
_EXPORT_STD template <class _Container, input_range _Rng, class... _Types>
requires (!view<_Container>)
_NODISCARD constexpr _Container to(_Rng&& _Range, _Types&&... _Args) {
static_assert(!is_const_v<_Container>, "C must not be const. ([range.utility.conv.to])");
static_assert(!is_volatile_v<_Container>, "C must not be volatile. ([range.utility.conv.to])");
static_assert(is_class_v<_Container>, "C must be a class type. ([range.utility.conv.to])");
if constexpr (_Converts_direct_constructible<_Rng, _Container, _Types...>) {
return _Container(_STD forward<_Rng>(_Range), _STD forward<_Types>(_Args)...);
} else if constexpr (_Converts_tag_constructible<_Rng, _Container, _Types...>) {
Expand All @@ -8427,6 +8430,9 @@ namespace ranges {

template <class _Container>
struct _To_class_fn {
_STL_INTERNAL_STATIC_ASSERT(!is_const_v<_Container>);
_STL_INTERNAL_STATIC_ASSERT(!is_volatile_v<_Container>);
_STL_INTERNAL_STATIC_ASSERT(is_class_v<_Container>);
_STL_INTERNAL_STATIC_ASSERT(!view<_Container>);

template <input_range _Rng, class... _Types>
Expand All @@ -8440,6 +8446,9 @@ namespace ranges {
_EXPORT_STD template <class _Container, class... _Types>
requires (!view<_Container>)
_NODISCARD constexpr auto to(_Types&&... _Args) {
static_assert(!is_const_v<_Container>, "C must not be const. ([range.utility.conv.adaptors])");
static_assert(!is_volatile_v<_Container>, "C must not be volatile. ([range.utility.conv.adaptors])");
static_assert(is_class_v<_Container>, "C must be a class type. ([range.utility.conv.adaptors])");
return _Range_closure<_To_class_fn<_Container>, decay_t<_Types>...>{_STD forward<_Types>(_Args)...};
}

Expand Down