File indexing completed on 2026-05-03 08:13:08
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef _LIBCPP___ALGORITHM_MINMAX_H
0010 #define _LIBCPP___ALGORITHM_MINMAX_H
0011
0012 #include <__algorithm/comp.h>
0013 #include <__algorithm/minmax_element.h>
0014 #include <__config>
0015 #include <__functional/identity.h>
0016 #include <__type_traits/is_callable.h>
0017 #include <__utility/pair.h>
0018 #include <initializer_list>
0019
0020 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0021 # pragma GCC system_header
0022 #endif
0023
0024 _LIBCPP_BEGIN_NAMESPACE_STD
0025
0026 template <class _Tp, class _Compare>
0027 [[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<const _Tp&, const _Tp&>
0028 minmax(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b, _Compare __comp) {
0029 return __comp(__b, __a) ? pair<const _Tp&, const _Tp&>(__b, __a) : pair<const _Tp&, const _Tp&>(__a, __b);
0030 }
0031
0032 template <class _Tp>
0033 [[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<const _Tp&, const _Tp&>
0034 minmax(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b) {
0035 return std::minmax(__a, __b, __less<>());
0036 }
0037
0038 #ifndef _LIBCPP_CXX03_LANG
0039
0040 template <class _Tp, class _Compare>
0041 [[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Tp, _Tp>
0042 minmax(initializer_list<_Tp> __t, _Compare __comp) {
0043 static_assert(__is_callable<_Compare&, _Tp, _Tp>::value, "The comparator has to be callable");
0044 __identity __proj;
0045 auto __ret = std::__minmax_element_impl(__t.begin(), __t.end(), __comp, __proj);
0046 return pair<_Tp, _Tp>(*__ret.first, *__ret.second);
0047 }
0048
0049 template <class _Tp>
0050 [[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Tp, _Tp>
0051 minmax(initializer_list<_Tp> __t) {
0052 return std::minmax(__t, __less<>());
0053 }
0054
0055 #endif
0056
0057 _LIBCPP_END_NAMESPACE_STD
0058
0059 #endif