Skip to content

Commit

Permalink
LWG-3847 ranges::to can still return views (#3479)
Browse files Browse the repository at this point in the history
Co-authored-by: Stephan T. Lavavej <[email protected]>
  • Loading branch information
mlemacio and StephanTLavavej authored Feb 23, 2023
1 parent be1ac63 commit 1bddf4c
Showing 1 changed file with 9 additions and 0 deletions.
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

0 comments on commit 1bddf4c

Please sign in to comment.