Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:13:10

0001 //===----------------------------------------------------------------------===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef _LIBCPP___ALGORITHM_RANGES_MIN_H
0010 #define _LIBCPP___ALGORITHM_RANGES_MIN_H
0011 
0012 #include <__algorithm/ranges_min_element.h>
0013 #include <__assert>
0014 #include <__concepts/copyable.h>
0015 #include <__config>
0016 #include <__functional/identity.h>
0017 #include <__functional/invoke.h>
0018 #include <__functional/ranges_operations.h>
0019 #include <__iterator/concepts.h>
0020 #include <__iterator/projected.h>
0021 #include <__ranges/access.h>
0022 #include <__ranges/concepts.h>
0023 #include <__type_traits/is_trivially_copyable.h>
0024 #include <initializer_list>
0025 
0026 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0027 #  pragma GCC system_header
0028 #endif
0029 
0030 #if _LIBCPP_STD_VER >= 20
0031 
0032 _LIBCPP_PUSH_MACROS
0033 #  include <__undef_macros>
0034 
0035 _LIBCPP_BEGIN_NAMESPACE_STD
0036 
0037 namespace ranges {
0038 struct __min {
0039   template <class _Tp,
0040             class _Proj                                                    = identity,
0041             indirect_strict_weak_order<projected<const _Tp*, _Proj>> _Comp = ranges::less>
0042   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr const _Tp&
0043   operator()(_LIBCPP_LIFETIMEBOUND const _Tp& __a,
0044              _LIBCPP_LIFETIMEBOUND const _Tp& __b,
0045              _Comp __comp = {},
0046              _Proj __proj = {}) const {
0047     return std::invoke(__comp, std::invoke(__proj, __b), std::invoke(__proj, __a)) ? __b : __a;
0048   }
0049 
0050   template <copyable _Tp,
0051             class _Proj                                                    = identity,
0052             indirect_strict_weak_order<projected<const _Tp*, _Proj>> _Comp = ranges::less>
0053   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp
0054   operator()(initializer_list<_Tp> __il, _Comp __comp = {}, _Proj __proj = {}) const {
0055     _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
0056         __il.begin() != __il.end(), "initializer_list must contain at least one element");
0057     return *ranges::__min_element_impl(__il.begin(), __il.end(), __comp, __proj);
0058   }
0059 
0060   template <input_range _Rp,
0061             class _Proj                                                         = identity,
0062             indirect_strict_weak_order<projected<iterator_t<_Rp>, _Proj>> _Comp = ranges::less>
0063     requires indirectly_copyable_storable<iterator_t<_Rp>, range_value_t<_Rp>*>
0064   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr range_value_t<_Rp>
0065   operator()(_Rp&& __r, _Comp __comp = {}, _Proj __proj = {}) const {
0066     auto __first = ranges::begin(__r);
0067     auto __last  = ranges::end(__r);
0068     _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__first != __last, "range must contain at least one element");
0069     if constexpr (forward_range<_Rp> && !__is_cheap_to_copy<range_value_t<_Rp>>) {
0070       return *ranges::__min_element_impl(__first, __last, __comp, __proj);
0071     } else {
0072       range_value_t<_Rp> __result = *__first;
0073       while (++__first != __last) {
0074         if (std::invoke(__comp, std::invoke(__proj, *__first), std::invoke(__proj, __result)))
0075           __result = *__first;
0076       }
0077       return __result;
0078     }
0079   }
0080 };
0081 
0082 inline namespace __cpo {
0083 inline constexpr auto min = __min{};
0084 } // namespace __cpo
0085 } // namespace ranges
0086 
0087 _LIBCPP_END_NAMESPACE_STD
0088 
0089 _LIBCPP_POP_MACROS
0090 
0091 #endif // _LIBCPP_STD_VER >= 20
0092 
0093 #endif // _LIBCPP___ALGORITHM_RANGES_MIN_H