From aca60ecff35837a1af9383cf67ee7d1c0a718b28 Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Wed, 19 Feb 2020 12:30:10 +0000 Subject: [PATCH] libstdc++: Add ranges_size_t and rename all_view (LWG 3335) * include/bits/range_access.h (range_size_t): Define alias template. * include/std/ranges (all_view): Rename to views::all_t (LWG 3335). * testsuite/std/ranges/adaptors/filter.cc: Adjust to new name. --- libstdc++-v3/ChangeLog | 4 ++ libstdc++-v3/include/bits/range_access.h | 3 ++ libstdc++-v3/include/std/ranges | 42 ++++++++++--------- .../testsuite/std/ranges/adaptors/filter.cc | 2 +- 4 files changed, 30 insertions(+), 21 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 9ccba4345d5..f01b78da118 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,9 @@ 2020-02-19 Jonathan Wakely + * include/bits/range_access.h (range_size_t): Define alias template. + * include/std/ranges (all_view): Rename to views::all_t (LWG 3335). + * testsuite/std/ranges/adaptors/filter.cc: Adjust to new name. + * include/std/ranges (filter_view, transform_view, take_view) (join_view, split_view, reverse_view): Remove commented-out converting constructors (LWG 3280). diff --git a/libstdc++-v3/include/bits/range_access.h b/libstdc++-v3/include/bits/range_access.h index e2a2c28c7d2..e7a19305d23 100644 --- a/libstdc++-v3/include/bits/range_access.h +++ b/libstdc++-v3/include/bits/range_access.h @@ -905,6 +905,9 @@ namespace ranges concept sized_range = range<_Tp> && requires(_Tp& __t) { ranges::size(__t); }; + template + using range_size_t = decltype(ranges::size(std::declval<_Range&>())); + // [range.refinements] /// A range for which ranges::begin returns an output iterator. diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges index cf4c19ffaab..b0806750a08 100644 --- a/libstdc++-v3/include/std/ranges +++ b/libstdc++-v3/include/std/ranges @@ -1236,10 +1236,11 @@ namespace views else return subrange{std::forward<_Range>(__r)}; }; - } // namespace views - template - using all_view = decltype(views::all(declval<_Range>())); + template + using all_t = decltype(all(std::declval<_Range>())); + + } // namespace views // XXX: the following algos are copied from ranges_algo.h to avoid a circular // dependency with that header. @@ -1503,7 +1504,7 @@ namespace views }; template - filter_view(_Range&&, _Pred) -> filter_view, _Pred>; + filter_view(_Range&&, _Pred) -> filter_view, _Pred>; namespace views { @@ -1836,7 +1837,7 @@ namespace views }; template - transform_view(_Range&&, _Fp) -> transform_view, _Fp>; + transform_view(_Range&&, _Fp) -> transform_view, _Fp>; namespace views { @@ -1974,7 +1975,7 @@ namespace views template take_view(_Range&&, range_difference_t<_Range>) - -> take_view>; + -> take_view>; namespace views { @@ -2066,7 +2067,7 @@ namespace views template take_while_view(_Range&&, _Pred) - -> take_while_view, _Pred>; + -> take_while_view, _Pred>; namespace views { @@ -2143,7 +2144,7 @@ namespace views template drop_view(_Range&&, range_difference_t<_Range>) - -> drop_view>; + -> drop_view>; namespace views { @@ -2199,7 +2200,7 @@ namespace views template drop_while_view(_Range&&, _Pred) - -> drop_while_view, _Pred>; + -> drop_while_view, _Pred>; namespace views { @@ -2450,7 +2451,7 @@ namespace views // XXX: _M_inner is "present only when !is_reference_v<_InnerRange>" [[no_unique_address]] conditional_t, - all_view<_InnerRange>, __detail::_Empty> _M_inner; + views::all_t<_InnerRange>, __detail::_Empty> _M_inner; public: join_view() = default; @@ -2514,7 +2515,7 @@ namespace views }; template - explicit join_view(_Range&&) -> join_view>; + explicit join_view(_Range&&) -> join_view>; namespace views { @@ -2838,7 +2839,7 @@ namespace views { } template - requires constructible_from<_Vp, all_view<_Range>> + requires constructible_from<_Vp, views::all_t<_Range>> && constructible_from<_Pattern, single_view>> constexpr split_view(_Range&& __r, range_value_t<_Range> __e) @@ -2893,11 +2894,11 @@ namespace views template split_view(_Range&&, _Pred&&) - -> split_view, all_view<_Pred>>; + -> split_view, views::all_t<_Pred>>; template split_view(_Range&&, range_value_t<_Range>) - -> split_view, single_view>>; + -> split_view, single_view>>; namespace views { @@ -2945,7 +2946,7 @@ namespace views /* XXX: LWG 3280 didn't remove this constructor, but I think it should? template requires (!common_range<_Range>) - && constructible_from<_Vp, all_view<_Range>> + && constructible_from<_Vp, views::all_t<_Range>> constexpr explicit common_view(_Range&& __r) : _M_base(views::all(std::forward<_Range>(__r))) @@ -3010,7 +3011,7 @@ namespace views }; template - common_view(_Range&&) -> common_view>; + common_view(_Range&&) -> common_view>; namespace views { @@ -3083,7 +3084,7 @@ namespace views }; template - reverse_view(_Range&&) -> reverse_view>; + reverse_view(_Range&&) -> reverse_view>; namespace views { @@ -3356,10 +3357,10 @@ namespace views }; template - using keys_view = elements_view, 0>; + using keys_view = elements_view, 0>; template - using values_view = elements_view, 1>; + using values_view = elements_view, 1>; namespace views { @@ -3367,7 +3368,8 @@ namespace views inline constexpr __adaptor::_RangeAdaptorClosure elements = [] (_Range&& __r) { - return elements_view, _Nm>{std::forward<_Range>(__r)}; + using _El = elements_view, _Nm>; + return _El{std::forward<_Range>(__r)}; }; inline constexpr __adaptor::_RangeAdaptorClosure keys = elements<0>; diff --git a/libstdc++-v3/testsuite/std/ranges/adaptors/filter.cc b/libstdc++-v3/testsuite/std/ranges/adaptors/filter.cc index 4edbf0b657d..4e41232cd5c 100644 --- a/libstdc++-v3/testsuite/std/ranges/adaptors/filter.cc +++ b/libstdc++-v3/testsuite/std/ranges/adaptors/filter.cc @@ -43,7 +43,7 @@ test01() static_assert(!ranges::sized_range); static_assert(ranges::bidirectional_range); static_assert(!ranges::random_access_range); - static_assert(ranges::range>); + static_assert(ranges::range>); VERIFY( ranges::equal(v, (int[]){1,3,5}) ); VERIFY( ranges::equal(v | views::reverse, (int[]){5,3,1}) ); VERIFY( v.pred()(3) == true ); -- 2.30.2