diff options
author | Andrey Khalyavin <halyavin@gmail.com> | 2022-04-15 02:46:40 +0300 |
---|---|---|
committer | Andrey Khalyavin <halyavin@gmail.com> | 2022-04-15 02:46:40 +0300 |
commit | c5bfd90690e2df55f55d1831b0edd2e1c7241582 (patch) | |
tree | cda6bc446bf17fc110b67126b4c5ddc640fa427b /contrib/libs/cxxsupp/libcxx/include/__ranges | |
parent | 599463a2ac4bda8536564ec6d7b798447755f05f (diff) | |
download | ydb-c5bfd90690e2df55f55d1831b0edd2e1c7241582.tar.gz |
Update libc++ to b6d87773 (14 Jan 2022).
Notable changes:
* implement operator << for filesystem::directory_entry
* add std::ranges::in_in_result
* add std::ranges::owning_view
* add std::ranges::cdata
* add std::ranges::construct_at and destroy{,_n,_at}
* small fixes in std::ranges::data
* SFINAE away std::ranges::cbegin(const T&&) for non-borrowed T
* use arc4random to implement std::random_device on Apple
* introduce __fits_in_sso to put constexpr check into a central place
* introduce __debug_db_insert_c to put #if and constexpr check into a central place
ref:b3dd06bd52f06e8939227ca0f0a5873d0c211e48
Diffstat (limited to 'contrib/libs/cxxsupp/libcxx/include/__ranges')
12 files changed, 164 insertions, 43 deletions
diff --git a/contrib/libs/cxxsupp/libcxx/include/__ranges/access.h b/contrib/libs/cxxsupp/libcxx/include/__ranges/access.h index 246f8b20ca..0b9470fa40 100644 --- a/contrib/libs/cxxsupp/libcxx/include/__ranges/access.h +++ b/contrib/libs/cxxsupp/libcxx/include/__ranges/access.h @@ -163,11 +163,12 @@ namespace ranges { namespace __cbegin { struct __fn { template <class _Tp> + requires is_lvalue_reference_v<_Tp&&> [[nodiscard]] _LIBCPP_HIDE_FROM_ABI - constexpr auto operator()(_Tp& __t) const - noexcept(noexcept(ranges::begin(static_cast<const _Tp&>(__t)))) - -> decltype( ranges::begin(static_cast<const _Tp&>(__t))) - { return ranges::begin(static_cast<const _Tp&>(__t)); } + constexpr auto operator()(_Tp&& __t) const + noexcept(noexcept(ranges::begin(static_cast<const remove_reference_t<_Tp>&>(__t)))) + -> decltype( ranges::begin(static_cast<const remove_reference_t<_Tp>&>(__t))) + { return ranges::begin(static_cast<const remove_reference_t<_Tp>&>(__t)); } template <class _Tp> requires is_rvalue_reference_v<_Tp&&> @@ -190,11 +191,12 @@ namespace ranges { namespace __cend { struct __fn { template <class _Tp> + requires is_lvalue_reference_v<_Tp&&> [[nodiscard]] _LIBCPP_HIDE_FROM_ABI - constexpr auto operator()(_Tp& __t) const - noexcept(noexcept(ranges::end(static_cast<const _Tp&>(__t)))) - -> decltype( ranges::end(static_cast<const _Tp&>(__t))) - { return ranges::end(static_cast<const _Tp&>(__t)); } + constexpr auto operator()(_Tp&& __t) const + noexcept(noexcept(ranges::end(static_cast<const remove_reference_t<_Tp>&>(__t)))) + -> decltype( ranges::end(static_cast<const remove_reference_t<_Tp>&>(__t))) + { return ranges::end(static_cast<const remove_reference_t<_Tp>&>(__t)); } template <class _Tp> requires is_rvalue_reference_v<_Tp&&> diff --git a/contrib/libs/cxxsupp/libcxx/include/__ranges/all.h b/contrib/libs/cxxsupp/libcxx/include/__ranges/all.h index ccc77258ba..90327da814 100644 --- a/contrib/libs/cxxsupp/libcxx/include/__ranges/all.h +++ b/contrib/libs/cxxsupp/libcxx/include/__ranges/all.h @@ -14,9 +14,9 @@ #include <__iterator/iterator_traits.h> #include <__ranges/access.h> #include <__ranges/concepts.h> +#include <__ranges/owning_view.h> #include <__ranges/range_adaptor.h> #include <__ranges/ref_view.h> -#include <__ranges/subrange.h> #include <__utility/auto_cast.h> #include <__utility/declval.h> #include <__utility/forward.h> @@ -56,12 +56,12 @@ namespace __all { template<class _Tp> requires (!ranges::view<decay_t<_Tp>> && !requires (_Tp&& __t) { ranges::ref_view{_VSTD::forward<_Tp>(__t)}; } && - requires (_Tp&& __t) { ranges::subrange{_VSTD::forward<_Tp>(__t)}; }) + requires (_Tp&& __t) { ranges::owning_view{_VSTD::forward<_Tp>(__t)}; }) [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const - noexcept(noexcept(ranges::subrange{_VSTD::forward<_Tp>(__t)})) + noexcept(noexcept(ranges::owning_view{_VSTD::forward<_Tp>(__t)})) { - return ranges::subrange{_VSTD::forward<_Tp>(__t)}; + return ranges::owning_view{_VSTD::forward<_Tp>(__t)}; } }; } diff --git a/contrib/libs/cxxsupp/libcxx/include/__ranges/concepts.h b/contrib/libs/cxxsupp/libcxx/include/__ranges/concepts.h index bad23c8c4b..fa31074ab6 100644 --- a/contrib/libs/cxxsupp/libcxx/include/__ranges/concepts.h +++ b/contrib/libs/cxxsupp/libcxx/include/__ranges/concepts.h @@ -9,6 +9,9 @@ #ifndef _LIBCPP___RANGES_CONCEPTS_H #define _LIBCPP___RANGES_CONCEPTS_H +#include <__concepts/constructible.h> +#include <__concepts/movable.h> +#include <__concepts/same_as.h> #include <__config> #include <__iterator/concepts.h> #include <__iterator/incrementable_traits.h> @@ -20,7 +23,7 @@ #include <__ranges/enable_borrowed_range.h> #include <__ranges/enable_view.h> #include <__ranges/size.h> -#include <concepts> +#include <initializer_list> #include <type_traits> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -114,12 +117,20 @@ namespace ranges { template <class _Tp> concept common_range = range<_Tp> && same_as<iterator_t<_Tp>, sentinel_t<_Tp>>; - template<class _Tp> + template <class _Tp> + inline constexpr bool __is_std_initializer_list = false; + + template <class _Ep> + inline constexpr bool __is_std_initializer_list<initializer_list<_Ep>> = true; + + template <class _Tp> concept viewable_range = - range<_Tp> && ( - (view<remove_cvref_t<_Tp>> && constructible_from<remove_cvref_t<_Tp>, _Tp>) || - (!view<remove_cvref_t<_Tp>> && borrowed_range<_Tp>) - ); + range<_Tp> && + ((view<remove_cvref_t<_Tp>> && constructible_from<remove_cvref_t<_Tp>, _Tp>) || + (!view<remove_cvref_t<_Tp>> && + (is_lvalue_reference_v<_Tp> || + (movable<remove_reference_t<_Tp>> && !__is_std_initializer_list<remove_cvref_t<_Tp>>)))); + } // namespace ranges #endif // !defined(_LIBCPP_HAS_NO_RANGES) diff --git a/contrib/libs/cxxsupp/libcxx/include/__ranges/copyable_box.h b/contrib/libs/cxxsupp/libcxx/include/__ranges/copyable_box.h index 4811690ada..c32596f17c 100644 --- a/contrib/libs/cxxsupp/libcxx/include/__ranges/copyable_box.h +++ b/contrib/libs/cxxsupp/libcxx/include/__ranges/copyable_box.h @@ -41,7 +41,7 @@ namespace ranges { // Primary template - uses std::optional and introduces an empty state in case assignment fails. template<__copy_constructible_object _Tp> class __copyable_box { - [[no_unique_address]] optional<_Tp> __val_; + _LIBCPP_NO_UNIQUE_ADDRESS optional<_Tp> __val_; public: template<class ..._Args> @@ -116,7 +116,7 @@ namespace ranges { template<__copy_constructible_object _Tp> requires __doesnt_need_empty_state_for_copy<_Tp> && __doesnt_need_empty_state_for_move<_Tp> class __copyable_box<_Tp> { - [[no_unique_address]] _Tp __val_; + _LIBCPP_NO_UNIQUE_ADDRESS _Tp __val_; public: template<class ..._Args> diff --git a/contrib/libs/cxxsupp/libcxx/include/__ranges/data.h b/contrib/libs/cxxsupp/libcxx/include/__ranges/data.h index cc151c59f3..69dfd479c0 100644 --- a/contrib/libs/cxxsupp/libcxx/include/__ranges/data.h +++ b/contrib/libs/cxxsupp/libcxx/include/__ranges/data.h @@ -9,13 +9,13 @@ #ifndef _LIBCPP___RANGES_DATA_H #define _LIBCPP___RANGES_DATA_H +#include <__concepts/class_or_enum.h> #include <__config> #include <__iterator/concepts.h> #include <__iterator/iterator_traits.h> #include <__memory/pointer_traits.h> #include <__ranges/access.h> -#include <__utility/forward.h> -#include <concepts> +#include <__utility/auto_cast.h> #include <type_traits> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -35,34 +35,33 @@ namespace __data { template <class _Tp> concept __member_data = + __can_borrow<_Tp> && + __workaround_52970<_Tp> && requires(_Tp&& __t) { - { _VSTD::forward<_Tp>(__t) } -> __can_borrow; - { __t.data() } -> __ptr_to_object; + { _LIBCPP_AUTO_CAST(__t.data()) } -> __ptr_to_object; }; template <class _Tp> concept __ranges_begin_invocable = !__member_data<_Tp> && + __can_borrow<_Tp> && requires(_Tp&& __t) { - { _VSTD::forward<_Tp>(__t) } -> __can_borrow; - { ranges::begin(_VSTD::forward<_Tp>(__t)) } -> contiguous_iterator; + { ranges::begin(__t) } -> contiguous_iterator; }; struct __fn { template <__member_data _Tp> - requires __can_borrow<_Tp> _LIBCPP_HIDE_FROM_ABI - constexpr __ptr_to_object auto operator()(_Tp&& __t) const + constexpr auto operator()(_Tp&& __t) const noexcept(noexcept(__t.data())) { return __t.data(); } template<__ranges_begin_invocable _Tp> - requires __can_borrow<_Tp> _LIBCPP_HIDE_FROM_ABI - constexpr __ptr_to_object auto operator()(_Tp&& __t) const - noexcept(noexcept(_VSTD::to_address(ranges::begin(_VSTD::forward<_Tp>(__t))))) { - return _VSTD::to_address(ranges::begin(_VSTD::forward<_Tp>(__t))); + constexpr auto operator()(_Tp&& __t) const + noexcept(noexcept(_VSTD::to_address(ranges::begin(__t)))) { + return _VSTD::to_address(ranges::begin(__t)); } }; } @@ -72,6 +71,34 @@ inline namespace __cpo { } // namespace __cpo } // namespace ranges +// [range.prim.cdata] + +namespace ranges { +namespace __cdata { + struct __fn { + template <class _Tp> + requires is_lvalue_reference_v<_Tp&&> + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI + constexpr auto operator()(_Tp&& __t) const + noexcept(noexcept(ranges::data(static_cast<const remove_reference_t<_Tp>&>(__t)))) + -> decltype( ranges::data(static_cast<const remove_reference_t<_Tp>&>(__t))) + { return ranges::data(static_cast<const remove_reference_t<_Tp>&>(__t)); } + + template <class _Tp> + requires is_rvalue_reference_v<_Tp&&> + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI + constexpr auto operator()(_Tp&& __t) const + noexcept(noexcept(ranges::data(static_cast<const _Tp&&>(__t)))) + -> decltype( ranges::data(static_cast<const _Tp&&>(__t))) + { return ranges::data(static_cast<const _Tp&&>(__t)); } + }; +} + +inline namespace __cpo { + inline constexpr auto cdata = __cdata::__fn{}; +} // namespace __cpo +} // namespace ranges + #endif // !defined(_LIBCPP_HAS_NO_RANGES) _LIBCPP_END_NAMESPACE_STD diff --git a/contrib/libs/cxxsupp/libcxx/include/__ranges/drop_view.h b/contrib/libs/cxxsupp/libcxx/include/__ranges/drop_view.h index 6adb09cf67..8d1ac87c93 100644 --- a/contrib/libs/cxxsupp/libcxx/include/__ranges/drop_view.h +++ b/contrib/libs/cxxsupp/libcxx/include/__ranges/drop_view.h @@ -45,7 +45,7 @@ namespace ranges { // one can't call begin() on it more than once. static constexpr bool _UseCache = forward_range<_View> && !(random_access_range<_View> && sized_range<_View>); using _Cache = _If<_UseCache, __non_propagating_cache<iterator_t<_View>>, __empty_cache>; - [[no_unique_address]] _Cache __cached_begin_ = _Cache(); + _LIBCPP_NO_UNIQUE_ADDRESS _Cache __cached_begin_ = _Cache(); range_difference_t<_View> __count_ = 0; _View __base_ = _View(); diff --git a/contrib/libs/cxxsupp/libcxx/include/__ranges/join_view.h b/contrib/libs/cxxsupp/libcxx/include/__ranges/join_view.h index 9aa69da76c..8dbafc7bd9 100644 --- a/contrib/libs/cxxsupp/libcxx/include/__ranges/join_view.h +++ b/contrib/libs/cxxsupp/libcxx/include/__ranges/join_view.h @@ -67,7 +67,7 @@ namespace ranges { static constexpr bool _UseCache = !is_reference_v<_InnerRange>; using _Cache = _If<_UseCache, __non_propagating_cache<remove_cvref_t<_InnerRange>>, __empty_cache>; - [[no_unique_address]] _Cache __cache_; + _LIBCPP_NO_UNIQUE_ADDRESS _Cache __cache_; _View __base_ = _View(); // TODO: [[no_unique_address]] makes clang crash! File a bug :) public: diff --git a/contrib/libs/cxxsupp/libcxx/include/__ranges/owning_view.h b/contrib/libs/cxxsupp/libcxx/include/__ranges/owning_view.h new file mode 100644 index 0000000000..29182d2d8e --- /dev/null +++ b/contrib/libs/cxxsupp/libcxx/include/__ranges/owning_view.h @@ -0,0 +1,81 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +#ifndef _LIBCPP___RANGES_OWNING_VIEW_H +#define _LIBCPP___RANGES_OWNING_VIEW_H + +#include <__concepts/constructible.h> +#include <__concepts/movable.h> +#include <__config> +#include <__ranges/access.h> +#include <__ranges/concepts.h> +#include <__ranges/data.h> +#include <__ranges/empty.h> +#include <__ranges/enable_borrowed_range.h> +#include <__ranges/size.h> +#include <__ranges/view_interface.h> +#include <__utility/move.h> +#include <type_traits> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if !defined(_LIBCPP_HAS_NO_RANGES) + +namespace ranges { + template<range _Rp> + requires movable<_Rp> && (!__is_std_initializer_list<remove_cvref_t<_Rp>>) + class owning_view : public view_interface<owning_view<_Rp>> { + _Rp __r_ = _Rp(); + +public: + owning_view() requires default_initializable<_Rp> = default; + _LIBCPP_HIDE_FROM_ABI constexpr owning_view(_Rp&& __r) : __r_(_VSTD::move(__r)) {} + + owning_view(owning_view&&) = default; + owning_view& operator=(owning_view&&) = default; + + _LIBCPP_HIDE_FROM_ABI constexpr _Rp& base() & noexcept { return __r_; } + _LIBCPP_HIDE_FROM_ABI constexpr const _Rp& base() const& noexcept { return __r_; } + _LIBCPP_HIDE_FROM_ABI constexpr _Rp&& base() && noexcept { return _VSTD::move(__r_); } + _LIBCPP_HIDE_FROM_ABI constexpr const _Rp&& base() const&& noexcept { return _VSTD::move(__r_); } + + _LIBCPP_HIDE_FROM_ABI constexpr iterator_t<_Rp> begin() { return ranges::begin(__r_); } + _LIBCPP_HIDE_FROM_ABI constexpr sentinel_t<_Rp> end() { return ranges::end(__r_); } + _LIBCPP_HIDE_FROM_ABI constexpr auto begin() const requires range<const _Rp> { return ranges::begin(__r_); } + _LIBCPP_HIDE_FROM_ABI constexpr auto end() const requires range<const _Rp> { return ranges::end(__r_); } + + _LIBCPP_HIDE_FROM_ABI constexpr bool empty() requires requires { ranges::empty(__r_); } + { return ranges::empty(__r_); } + _LIBCPP_HIDE_FROM_ABI constexpr bool empty() const requires requires { ranges::empty(__r_); } + { return ranges::empty(__r_); } + + _LIBCPP_HIDE_FROM_ABI constexpr auto size() requires sized_range<_Rp> + { return ranges::size(__r_); } + _LIBCPP_HIDE_FROM_ABI constexpr auto size() const requires sized_range<const _Rp> + { return ranges::size(__r_); } + + _LIBCPP_HIDE_FROM_ABI constexpr auto data() requires contiguous_range<_Rp> + { return ranges::data(__r_); } + _LIBCPP_HIDE_FROM_ABI constexpr auto data() const requires contiguous_range<const _Rp> + { return ranges::data(__r_); } + }; + + template<class _Tp> + inline constexpr bool enable_borrowed_range<owning_view<_Tp>> = enable_borrowed_range<_Tp>; + +} // namespace ranges + +#endif // !defined(_LIBCPP_HAS_NO_RANGES) + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___RANGES_OWNING_VIEW_H diff --git a/contrib/libs/cxxsupp/libcxx/include/__ranges/reverse_view.h b/contrib/libs/cxxsupp/libcxx/include/__ranges/reverse_view.h index 618be80457..f46df52259 100644 --- a/contrib/libs/cxxsupp/libcxx/include/__ranges/reverse_view.h +++ b/contrib/libs/cxxsupp/libcxx/include/__ranges/reverse_view.h @@ -43,8 +43,8 @@ namespace ranges { // amortized O(1) begin() method. static constexpr bool _UseCache = !random_access_range<_View> && !common_range<_View>; using _Cache = _If<_UseCache, __non_propagating_cache<reverse_iterator<iterator_t<_View>>>, __empty_cache>; - [[no_unique_address]] _Cache __cached_begin_ = _Cache(); - [[no_unique_address]] _View __base_ = _View(); + _LIBCPP_NO_UNIQUE_ADDRESS _Cache __cached_begin_ = _Cache(); + _LIBCPP_NO_UNIQUE_ADDRESS _View __base_ = _View(); public: _LIBCPP_HIDE_FROM_ABI diff --git a/contrib/libs/cxxsupp/libcxx/include/__ranges/subrange.h b/contrib/libs/cxxsupp/libcxx/include/__ranges/subrange.h index 8e984f2bf0..76adbffef6 100644 --- a/contrib/libs/cxxsupp/libcxx/include/__ranges/subrange.h +++ b/contrib/libs/cxxsupp/libcxx/include/__ranges/subrange.h @@ -80,9 +80,9 @@ namespace ranges { static constexpr bool _MustProvideSizeAtConstruction = !_StoreSize; // just to improve compiler diagnostics struct _Empty { constexpr _Empty(auto) noexcept { } }; using _Size = conditional_t<_StoreSize, make_unsigned_t<iter_difference_t<_Iter>>, _Empty>; - [[no_unique_address]] _Iter __begin_ = _Iter(); - [[no_unique_address]] _Sent __end_ = _Sent(); - [[no_unique_address]] _Size __size_ = 0; + _LIBCPP_NO_UNIQUE_ADDRESS _Iter __begin_ = _Iter(); + _LIBCPP_NO_UNIQUE_ADDRESS _Sent __end_ = _Sent(); + _LIBCPP_NO_UNIQUE_ADDRESS _Size __size_ = 0; public: _LIBCPP_HIDE_FROM_ABI diff --git a/contrib/libs/cxxsupp/libcxx/include/__ranges/take_view.h b/contrib/libs/cxxsupp/libcxx/include/__ranges/take_view.h index 73a57fe96c..b1d6ab2afa 100644 --- a/contrib/libs/cxxsupp/libcxx/include/__ranges/take_view.h +++ b/contrib/libs/cxxsupp/libcxx/include/__ranges/take_view.h @@ -39,7 +39,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD namespace ranges { template<view _View> class take_view : public view_interface<take_view<_View>> { - [[no_unique_address]] _View __base_ = _View(); + _LIBCPP_NO_UNIQUE_ADDRESS _View __base_ = _View(); range_difference_t<_View> __count_ = 0; template<bool> class __sentinel; @@ -136,7 +136,7 @@ namespace ranges { using _Base = __maybe_const<_Const, _View>; template<bool _OtherConst> using _Iter = counted_iterator<iterator_t<__maybe_const<_OtherConst, _View>>>; - [[no_unique_address]] sentinel_t<_Base> __end_ = sentinel_t<_Base>(); + _LIBCPP_NO_UNIQUE_ADDRESS sentinel_t<_Base> __end_ = sentinel_t<_Base>(); template<bool> friend class take_view<_View>::__sentinel; diff --git a/contrib/libs/cxxsupp/libcxx/include/__ranges/transform_view.h b/contrib/libs/cxxsupp/libcxx/include/__ranges/transform_view.h index 0f53fbaa7e..020f51af8c 100644 --- a/contrib/libs/cxxsupp/libcxx/include/__ranges/transform_view.h +++ b/contrib/libs/cxxsupp/libcxx/include/__ranges/transform_view.h @@ -62,8 +62,8 @@ class transform_view : public view_interface<transform_view<_View, _Fn>> { template<bool> class __iterator; template<bool> class __sentinel; - [[no_unique_address]] __copyable_box<_Fn> __func_; - [[no_unique_address]] _View __base_ = _View(); + _LIBCPP_NO_UNIQUE_ADDRESS __copyable_box<_Fn> __func_; + _LIBCPP_NO_UNIQUE_ADDRESS _View __base_ = _View(); public: _LIBCPP_HIDE_FROM_ABI |