diff options
author | hiddenpath <hiddenpath@yandex-team.com> | 2024-02-21 23:16:42 +0300 |
---|---|---|
committer | hiddenpath <hiddenpath@yandex-team.com> | 2024-02-21 23:33:25 +0300 |
commit | 9052eb5cc304b8da8885fc4e3364ebddc16945f3 (patch) | |
tree | 3c252f6161dd0745c7732d74c9304c000645ab47 /contrib/libs/cxxsupp/libcxx/include/__algorithm/ranges_minmax.h | |
parent | f5eb715f103692e7c7536e13bef3f281fd78e5e7 (diff) | |
download | ydb-9052eb5cc304b8da8885fc4e3364ebddc16945f3.tar.gz |
Update libcxx to llvmorg-17.0.6
Update libcxx to llvmorg-17.0.6
c871ef572c71b4fef22d4a9e65bcebc57e625aea
Diffstat (limited to 'contrib/libs/cxxsupp/libcxx/include/__algorithm/ranges_minmax.h')
-rw-r--r-- | contrib/libs/cxxsupp/libcxx/include/__algorithm/ranges_minmax.h | 63 |
1 files changed, 44 insertions, 19 deletions
diff --git a/contrib/libs/cxxsupp/libcxx/include/__algorithm/ranges_minmax.h b/contrib/libs/cxxsupp/libcxx/include/__algorithm/ranges_minmax.h index f82e00551e..a5b5cf9bd0 100644 --- a/contrib/libs/cxxsupp/libcxx/include/__algorithm/ranges_minmax.h +++ b/contrib/libs/cxxsupp/libcxx/include/__algorithm/ranges_minmax.h @@ -13,14 +13,18 @@ #include <__algorithm/minmax_element.h> #include <__assert> #include <__concepts/copyable.h> +#include <__concepts/same_as.h> #include <__config> #include <__functional/identity.h> #include <__functional/invoke.h> #include <__functional/ranges_operations.h> #include <__iterator/concepts.h> +#include <__iterator/next.h> #include <__iterator/projected.h> #include <__ranges/access.h> #include <__ranges/concepts.h> +#include <__type_traits/is_reference.h> +#include <__type_traits/remove_cvref.h> #include <__utility/forward.h> #include <__utility/move.h> #include <__utility/pair.h> @@ -30,10 +34,10 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER > 17 +#if _LIBCPP_STD_VER >= 20 _LIBCPP_PUSH_MACROS -#include <__undef_macros> +# include <__undef_macros> _LIBCPP_BEGIN_NAMESPACE_STD @@ -43,46 +47,67 @@ using minmax_result = min_max_result<_T1>; namespace __minmax { struct __fn { - template <class _Type, class _Proj = identity, + template <class _Type, + class _Proj = identity, indirect_strict_weak_order<projected<const _Type*, _Proj>> _Comp = ranges::less> _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr ranges::minmax_result<const _Type&> - operator()(const _Type& __a, const _Type& __b, _Comp __comp = {}, _Proj __proj = {}) const { + operator()(_LIBCPP_LIFETIMEBOUND const _Type& __a, + _LIBCPP_LIFETIMEBOUND const _Type& __b, + _Comp __comp = {}, + _Proj __proj = {}) const { if (std::invoke(__comp, std::invoke(__proj, __b), std::invoke(__proj, __a))) return {__b, __a}; return {__a, __b}; } - template <copyable _Type, class _Proj = identity, + template <copyable _Type, + class _Proj = identity, indirect_strict_weak_order<projected<const _Type*, _Proj>> _Comp = ranges::less> - _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr - ranges::minmax_result<_Type> operator()(initializer_list<_Type> __il, _Comp __comp = {}, _Proj __proj = {}) const { - _LIBCPP_ASSERT(__il.begin() != __il.end(), "initializer_list has to contain at least one element"); + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr ranges::minmax_result<_Type> + operator()(initializer_list<_Type> __il, _Comp __comp = {}, _Proj __proj = {}) const { + _LIBCPP_ASSERT_UNCATEGORIZED(__il.begin() != __il.end(), "initializer_list has to contain at least one element"); auto __iters = std::__minmax_element_impl(__il.begin(), __il.end(), __comp, __proj); - return ranges::minmax_result<_Type> { *__iters.first, *__iters.second }; + return ranges::minmax_result<_Type>{*__iters.first, *__iters.second}; } - template <input_range _Range, class _Proj = identity, + template <input_range _Range, + class _Proj = identity, indirect_strict_weak_order<projected<iterator_t<_Range>, _Proj>> _Comp = ranges::less> requires indirectly_copyable_storable<iterator_t<_Range>, range_value_t<_Range>*> - _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr - ranges::minmax_result<range_value_t<_Range>> operator()(_Range&& __r, _Comp __comp = {}, _Proj __proj = {}) const { - auto __first = ranges::begin(__r); - auto __last = ranges::end(__r); + _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr ranges::minmax_result<range_value_t<_Range>> + operator()(_Range&& __r, _Comp __comp = {}, _Proj __proj = {}) const { + auto __first = ranges::begin(__r); + auto __last = ranges::end(__r); using _ValueT = range_value_t<_Range>; - _LIBCPP_ASSERT(__first != __last, "range has to contain at least one element"); + _LIBCPP_ASSERT_UNCATEGORIZED(__first != __last, "range has to contain at least one element"); if constexpr (forward_range<_Range>) { + // Special-case the one element case. Avoid repeatedly initializing objects from the result of an iterator + // dereference when doing so might not be idempotent. The `if constexpr` avoids the extra branch in cases where + // it's not needed. + if constexpr (!same_as<remove_cvref_t<range_reference_t<_Range>>, _ValueT> || + is_rvalue_reference_v<range_reference_t<_Range>>) { + if (ranges::next(__first) == __last) { + // During initialization, members are allowed to refer to already initialized members + // (see http://eel.is/c++draft/dcl.init.aggr#6) + minmax_result<_ValueT> __result = {*__first, __result.min}; + return __result; + } + } auto __result = std::__minmax_element_impl(__first, __last, __comp, __proj); return {*__result.first, *__result.second}; } else { // input_iterators can't be copied, so the implementation for input_iterators has to store // the values instead of a pointer to the correct values auto __less = [&](auto&& __a, auto&& __b) -> bool { - return std::invoke(__comp, std::invoke(__proj, std::forward<decltype(__a)>(__a)), - std::invoke(__proj, std::forward<decltype(__b)>(__b))); + return std::invoke(__comp, + std::invoke(__proj, std::forward<decltype(__a)>(__a)), + std::invoke(__proj, std::forward<decltype(__b)>(__b))); }; + // During initialization, members are allowed to refer to already initialized members + // (see http://eel.is/c++draft/dcl.init.aggr#6) ranges::minmax_result<_ValueT> __result = {*__first, __result.min}; if (__first == __last || ++__first == __last) return __result; @@ -121,7 +146,7 @@ struct __fn { } // namespace __minmax inline namespace __cpo { - inline constexpr auto minmax = __minmax::__fn{}; +inline constexpr auto minmax = __minmax::__fn{}; } // namespace __cpo } // namespace ranges @@ -129,6 +154,6 @@ _LIBCPP_END_NAMESPACE_STD _LIBCPP_POP_MACROS -#endif // _LIBCPP_STD_VER > 17 +#endif // _LIBCPP_STD_VER >= 20 #endif // _LIBCPP___ALGORITHM_RANGES_MINMAX_H |