File indexing completed on 2026-05-03 08:13:20
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef _LIBCPP___CXX03___ALGORITHM_RANGES_MIN_H
0010 #define _LIBCPP___CXX03___ALGORITHM_RANGES_MIN_H
0011
0012 #include <__cxx03/__algorithm/ranges_min_element.h>
0013 #include <__cxx03/__assert>
0014 #include <__cxx03/__concepts/copyable.h>
0015 #include <__cxx03/__config>
0016 #include <__cxx03/__functional/identity.h>
0017 #include <__cxx03/__functional/invoke.h>
0018 #include <__cxx03/__functional/ranges_operations.h>
0019 #include <__cxx03/__iterator/concepts.h>
0020 #include <__cxx03/__iterator/projected.h>
0021 #include <__cxx03/__ranges/access.h>
0022 #include <__cxx03/__ranges/concepts.h>
0023 #include <__cxx03/__type_traits/is_trivially_copyable.h>
0024 #include <__cxx03/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 <__cxx03/__undef_macros>
0034
0035 _LIBCPP_BEGIN_NAMESPACE_STD
0036
0037 namespace ranges {
0038 namespace __min {
0039 struct __fn {
0040 template <class _Tp,
0041 class _Proj = identity,
0042 indirect_strict_weak_order<projected<const _Tp*, _Proj>> _Comp = ranges::less>
0043 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr const _Tp&
0044 operator()(_LIBCPP_LIFETIMEBOUND const _Tp& __a,
0045 _LIBCPP_LIFETIMEBOUND const _Tp& __b,
0046 _Comp __comp = {},
0047 _Proj __proj = {}) const {
0048 return std::invoke(__comp, std::invoke(__proj, __b), std::invoke(__proj, __a)) ? __b : __a;
0049 }
0050
0051 template <copyable _Tp,
0052 class _Proj = identity,
0053 indirect_strict_weak_order<projected<const _Tp*, _Proj>> _Comp = ranges::less>
0054 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp
0055 operator()(initializer_list<_Tp> __il, _Comp __comp = {}, _Proj __proj = {}) const {
0056 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
0057 __il.begin() != __il.end(), "initializer_list must contain at least one element");
0058 return *ranges::__min_element_impl(__il.begin(), __il.end(), __comp, __proj);
0059 }
0060
0061 template <input_range _Rp,
0062 class _Proj = identity,
0063 indirect_strict_weak_order<projected<iterator_t<_Rp>, _Proj>> _Comp = ranges::less>
0064 requires indirectly_copyable_storable<iterator_t<_Rp>, range_value_t<_Rp>*>
0065 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr range_value_t<_Rp>
0066 operator()(_Rp&& __r, _Comp __comp = {}, _Proj __proj = {}) const {
0067 auto __first = ranges::begin(__r);
0068 auto __last = ranges::end(__r);
0069 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__first != __last, "range must contain at least one element");
0070 if constexpr (forward_range<_Rp> && !__is_cheap_to_copy<range_value_t<_Rp>>) {
0071 return *ranges::__min_element_impl(__first, __last, __comp, __proj);
0072 } else {
0073 range_value_t<_Rp> __result = *__first;
0074 while (++__first != __last) {
0075 if (std::invoke(__comp, std::invoke(__proj, *__first), std::invoke(__proj, __result)))
0076 __result = *__first;
0077 }
0078 return __result;
0079 }
0080 }
0081 };
0082 }
0083
0084 inline namespace __cpo {
0085 inline constexpr auto min = __min::__fn{};
0086 }
0087 }
0088
0089 _LIBCPP_END_NAMESPACE_STD
0090
0091 _LIBCPP_POP_MACROS
0092
0093 #endif
0094
0095 #endif