Back to home page

EIC code displayed by LXR

 
 

    


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

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___CXX03___ALGORITHM_MINMAX_H
0010 #define _LIBCPP___CXX03___ALGORITHM_MINMAX_H
0011 
0012 #include <__cxx03/__algorithm/comp.h>
0013 #include <__cxx03/__algorithm/minmax_element.h>
0014 #include <__cxx03/__config>
0015 #include <__cxx03/__functional/identity.h>
0016 #include <__cxx03/__type_traits/is_callable.h>
0017 #include <__cxx03/__utility/pair.h>
0018 #include <__cxx03/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 _LIBCPP_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 _LIBCPP_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 _LIBCPP_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 _LIBCPP_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 // _LIBCPP_CXX03_LANG
0056 
0057 _LIBCPP_END_NAMESPACE_STD
0058 
0059 #endif // _LIBCPP___CXX03___ALGORITHM_MINMAX_H