Skip to content

Commit

Permalink
Moved cv check into static assert
Browse files Browse the repository at this point in the history
  • Loading branch information
mlemacio committed Feb 18, 2023
1 parent 7c4e44c commit 546023b
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions stl/inc/ranges
Original file line number Diff line number Diff line change
Expand Up @@ -8399,15 +8399,11 @@ namespace ranges {
}
}

// clang-format off
template <class _Container>
concept _Is_cv_unqualified = !is_const_v<_Container> && !is_volatile_v<_Container>;
// clang-format on


_EXPORT_STD template <class _Container, input_range _Rng, class... _Types>
requires (_Is_cv_unqualified<_Container> && !view<_Container>)
requires (!view<_Container>)
_NODISCARD constexpr _Container to(_Rng&& _Range, _Types&&... _Args) {
static_assert(!is_const_v<_Container>, "the target type must be cv-unqualified");
static_assert(!is_volatile_v<_Container>, "the target type must be cv-unqualified");
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 @@ -8433,7 +8429,8 @@ namespace ranges {

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

template <input_range _Rng, class... _Types>
Expand All @@ -8445,8 +8442,10 @@ namespace ranges {
};

_EXPORT_STD template <class _Container, class... _Types>
requires (_Is_cv_unqualified<_Container> && !view<_Container>)
requires (!view<_Container>)
_NODISCARD constexpr auto to(_Types&&... _Args) {
static_assert(!is_const_v<_Container>, "the target type must be cv-unqualified");
static_assert(!is_volatile_v<_Container>, "the target type must be cv-unqualified");
return _Range_closure<_To_class_fn<_Container>, decay_t<_Types>...>{_STD forward<_Types>(_Args)...};
}

Expand Down

0 comments on commit 546023b

Please sign in to comment.