diff options
author | Patrick Palka <ppalka@redhat.com> | 2022-02-22 09:37:58 -0500 |
---|---|---|
committer | Patrick Palka <ppalka@redhat.com> | 2022-02-22 09:37:58 -0500 |
commit | 5e1b17f038671df1a6580ece4cd58ef91cc1e234 (patch) | |
tree | d2fec60efe254b26c408c5cbb3c166f090bca081 /libstdc++-v3/include/std | |
parent | bc91cb8d8cf1d4abbb74fb69d918071e1801fd77 (diff) | |
download | gcc-5e1b17f038671df1a6580ece4cd58ef91cc1e234.zip gcc-5e1b17f038671df1a6580ece4cd58ef91cc1e234.tar.gz gcc-5e1b17f038671df1a6580ece4cd58ef91cc1e234.tar.bz2 |
libstdc++: Implement P2415R2 changes to viewable_range / views::all
This implements the wording changes in P2415R2 "What is a view?", which
is a DR for C++20.
libstdc++-v3/ChangeLog:
* include/bits/ranges_base.h (__detail::__is_initializer_list):
Define.
(viewable_range): Adjust as per P2415R2.
* include/bits/ranges_cmp.h (__cpp_lib_ranges): Adjust value.
* include/std/ranges (owning_view): Define as per P2415R2.
(enable_borrowed_range<owning_view>): Likewise.
(views::__detail::__can_subrange): Replace with ...
(views::__detail::__can_owning_view): ... this.
(views::_All::_S_noexcept): Sync with operator().
(views::_All::operator()): Use owning_view instead of subrange
as per P2415R2.
* include/std/version (__cpp_lib_ranges): Adjust value.
* testsuite/std/ranges/adaptors/all.cc (test06): Adjust now that
views::all uses owning_view instead of subrange.
(test08): New test.
* testsuite/std/ranges/adaptors/lazy_split.cc (test09): Adjust
now that rvalue non-view non-borrowed ranges are viewable.
* testsuite/std/ranges/adaptors/split.cc (test06): Likewise.
Diffstat (limited to 'libstdc++-v3/include/std')
-rw-r--r-- | libstdc++-v3/include/std/ranges | 89 | ||||
-rw-r--r-- | libstdc++-v3/include/std/version | 2 |
2 files changed, 86 insertions, 5 deletions
diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges index ac85907..3e71ecb 100644 --- a/libstdc++-v3/include/std/ranges +++ b/libstdc++-v3/include/std/ranges @@ -1144,6 +1144,87 @@ namespace views::__adaptor template<typename _Tp> inline constexpr bool enable_borrowed_range<ref_view<_Tp>> = true; + template<range _Range> + requires movable<_Range> + && (!__detail::__is_initializer_list<remove_cv_t<_Range>>) + class owning_view : public view_interface<owning_view<_Range>> + { + private: + _Range _M_r = _Range(); + + public: + owning_view() requires default_initializable<_Range> = default; + + constexpr + owning_view(_Range&& __t) + noexcept(is_nothrow_move_constructible_v<_Range>) + : _M_r(std::move(__t)) + { } + + owning_view(owning_view&&) = default; + owning_view& operator=(owning_view&&) = default; + + constexpr _Range& + base() & noexcept + { return _M_r; } + + constexpr const _Range& + base() const& noexcept + { return _M_r; } + + constexpr _Range&& + base() && noexcept + { return std::move(_M_r); } + + constexpr const _Range&& + base() const&& noexcept + { return std::move(_M_r); } + + constexpr iterator_t<_Range> + begin() + { return ranges::begin(_M_r); } + + constexpr sentinel_t<_Range> + end() + { return ranges::end(_M_r); } + + constexpr auto + begin() const requires range<const _Range> + { return ranges::begin(_M_r); } + + constexpr auto + end() const requires range<const _Range> + { return ranges::end(_M_r); } + + constexpr bool + empty() requires requires { ranges::empty(_M_r); } + { return ranges::empty(_M_r); } + + constexpr bool + empty() const requires requires { ranges::empty(_M_r); } + { return ranges::empty(_M_r); } + + constexpr auto + size() requires sized_range<_Range> + { return ranges::size(_M_r); } + + constexpr auto + size() const requires sized_range<const _Range> + { return ranges::size(_M_r); } + + constexpr auto + data() requires contiguous_range<_Range> + { return ranges::data(_M_r); } + + constexpr auto + data() const requires contiguous_range<const _Range> + { return ranges::data(_M_r); } + }; + + template<typename _Tp> + inline constexpr bool enable_borrowed_range<owning_view<_Tp>> + = enable_borrowed_range<_Tp>; + namespace views { namespace __detail @@ -1152,7 +1233,7 @@ namespace views::__adaptor concept __can_ref_view = requires { ref_view{std::declval<_Range>()}; }; template<typename _Range> - concept __can_subrange = requires { subrange{std::declval<_Range>()}; }; + concept __can_owning_view = requires { owning_view{std::declval<_Range>()}; }; } // namespace __detail struct _All : __adaptor::_RangeAdaptorClosure @@ -1166,13 +1247,13 @@ namespace views::__adaptor else if constexpr (__detail::__can_ref_view<_Range>) return true; else - return noexcept(subrange{std::declval<_Range>()}); + return noexcept(owning_view{std::declval<_Range>()}); } template<viewable_range _Range> requires view<decay_t<_Range>> || __detail::__can_ref_view<_Range> - || __detail::__can_subrange<_Range> + || __detail::__can_owning_view<_Range> constexpr auto operator() [[nodiscard]] (_Range&& __r) const noexcept(_S_noexcept<_Range>()) @@ -1182,7 +1263,7 @@ namespace views::__adaptor else if constexpr (__detail::__can_ref_view<_Range>) return ref_view{std::forward<_Range>(__r)}; else - return subrange{std::forward<_Range>(__r)}; + return owning_view{std::forward<_Range>(__r)}; } static constexpr bool _S_has_simple_call_op = true; diff --git a/libstdc++-v3/include/std/version b/libstdc++-v3/include/std/version index 24311ee..461e65b 100644 --- a/libstdc++-v3/include/std/version +++ b/libstdc++-v3/include/std/version @@ -273,7 +273,7 @@ #define __cpp_lib_optional 202106L #define __cpp_lib_polymorphic_allocator 201902L #if __cpp_lib_concepts -# define __cpp_lib_ranges 202106L +# define __cpp_lib_ranges 202110L #endif #if __cpp_lib_atomic_wait || _GLIBCXX_HAVE_POSIX_SEMAPHORE # define __cpp_lib_semaphore 201907L |