Tested x86_64-linux. Pushed to trunk. -- >8 --
Fix some errors that Patrick noticed, and remove a #if 0 group that I didn't mean to leave in the file. libstdc++-v3/ChangeLog: * include/std/ranges (__detail::__toable): Fix incorrect use of _Range instead of _Cont. (__detail::_ToClosure, __detail::_ToClosure2): Add missing constexpr specifier on constructors. * testsuite/std/ranges/conv/1.cc (_Cont, _Cont2, _Cont3): Remove unnecessary begin() and end() members. (test_constexpr): New function to check range adaptors are usable in constant expressions. --- libstdc++-v3/include/std/ranges | 26 +++--------------- libstdc++-v3/testsuite/std/ranges/conv/1.cc | 29 +++++++++++---------- 2 files changed, 19 insertions(+), 36 deletions(-) diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges index 63bea862c05..9d4c2e01c4d 100644 --- a/libstdc++-v3/include/std/ranges +++ b/libstdc++-v3/include/std/ranges @@ -9251,7 +9251,7 @@ namespace __detail template<typename _Cont, typename _Range> constexpr bool __toable = requires { - requires (!input_range<_Range> + requires (!input_range<_Cont> || convertible_to<range_reference_t<_Range>, range_value_t<_Cont>>); }; @@ -9290,7 +9290,7 @@ namespace __detail else if constexpr (constructible_from<_Cont, from_range_t, _Rg, _Args...>) return _Cont(from_range, std::forward<_Rg>(__r), std::forward<_Args>(__args)...); - else if constexpr (requires { common_range<_Rg>; + else if constexpr (requires { requires common_range<_Rg>; typename __iter_category_t<iterator_t<_Rg>>; requires derived_from<__iter_category_t<iterator_t<_Rg>>, input_iterator_tag>; @@ -9346,26 +9346,6 @@ namespace __detail bool operator==(const _InputIter&) const; }; -#if 0 - template<template<typename...> typename _Cont, typename _Rg, - typename... _Args> - concept __deduce_expr_1 = requires { - _Cont(std::declval<_Rg>(), std::declval<_Args>()...); - }; - - template<template<typename...> typename _Cont, typename _Rg, - typename... _Args> - concept __deduce_expr_2 = requires { - _Cont(from_range, std::declval<_Rg>(), std::declval<_Args>()...); - }; - - template<template<typename...> typename _Cont, typename _Rg, - typename... _Args> - concept __deduce_expr_3 = requires(_InputIter<_Rg> __i) { - _Cont(std::move(__i), std::move(__i), std::declval<_Args>()...); - }; -#endif - template<template<typename...> typename _Cont, input_range _Rg, typename... _Args> using _DeduceExpr1 @@ -9418,6 +9398,7 @@ namespace __detail tuple<decay_t<_Args>...> _M_bound_args; public: + constexpr _ToClosure(_Args&&... __args) : _M_bound_args(std::forward<_Args>(__args)...) { } @@ -9498,6 +9479,7 @@ namespace __detail tuple<decay_t<_Args>...> _M_bound_args; public: + constexpr _ToClosure2(_Args&&... __args) : _M_bound_args(std::forward<_Args>(__args)...) { } diff --git a/libstdc++-v3/testsuite/std/ranges/conv/1.cc b/libstdc++-v3/testsuite/std/ranges/conv/1.cc index 0032cf32688..4b6814b1add 100644 --- a/libstdc++-v3/testsuite/std/ranges/conv/1.cc +++ b/libstdc++-v3/testsuite/std/ranges/conv/1.cc @@ -89,9 +89,6 @@ struct Cont1 : c(r, args...) { } - typename C::iterator begin(); - typename C::iterator end(); - C c; }; @@ -153,9 +150,6 @@ struct Cont2 : c(r, args...) { } - typename C::iterator begin(); - typename C::iterator end(); - C c; }; @@ -186,9 +180,6 @@ struct Cont3 : c(first, last, args...) { } - typename C::iterator begin(); - typename C::iterator end(); - C c; }; @@ -222,10 +213,6 @@ struct Cont4 Cont4() { } Cont4(typename C::allocator_type a) : c(a) { } - // Required to satisfy range - typename C::iterator begin() { return c.begin(); } - typename C::iterator end() { return c.end(); } - // Satisfying container-insertable requires either this ... template<typename T> requires UsePushBack @@ -254,7 +241,9 @@ struct Cont4 used_reserve = true; } - // Required to satisfy reservable-container + // Satisfying sized_range is required to satisfy reservable-container + typename C::iterator begin() { return c.begin(); } + typename C::iterator end() { return c.end(); } auto size() const { return c.size(); } // Required to satisfy reservable-container @@ -355,6 +344,17 @@ test_nodiscard() std::ranges::to<std::vector>(); // { dg-warning "ignoring return" } } +void +test_constexpr() +{ + constexpr int x = [](int i) { + auto c1 = std::views::iota(1, i) | std::ranges::to<std::vector<int>>(); + auto c2 = std::views::iota(i, 10) | std::ranges::to<std::vector>(); + return c1[0] + c2[0]; + }(5); + static_assert(x == 6); +} + int main() { test_p1206r7_examples(); @@ -366,4 +366,5 @@ int main() test_2_2(); test_lwg3984(); test_nodiscard(); + test_constexpr(); } -- 2.43.0