[RISCV] Add MIPS P8700 processor (#119882)
[llvm-project.git] / libcxx / include / __cxx03 / __algorithm / minmax.h
blobe09a5b04104aadf43a0953f6627a57d6e5f84a4f
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #ifndef _LIBCPP___CXX03___ALGORITHM_MINMAX_H
10 #define _LIBCPP___CXX03___ALGORITHM_MINMAX_H
12 #include <__cxx03/__algorithm/comp.h>
13 #include <__cxx03/__algorithm/minmax_element.h>
14 #include <__cxx03/__config>
15 #include <__cxx03/__functional/identity.h>
16 #include <__cxx03/__type_traits/is_callable.h>
17 #include <__cxx03/__utility/pair.h>
18 #include <__cxx03/initializer_list>
20 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
21 # pragma GCC system_header
22 #endif
24 _LIBCPP_BEGIN_NAMESPACE_STD
26 template <class _Tp, class _Compare>
27 _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<const _Tp&, const _Tp&>
28 minmax(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b, _Compare __comp) {
29 return __comp(__b, __a) ? pair<const _Tp&, const _Tp&>(__b, __a) : pair<const _Tp&, const _Tp&>(__a, __b);
32 template <class _Tp>
33 _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<const _Tp&, const _Tp&>
34 minmax(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b) {
35 return std::minmax(__a, __b, __less<>());
38 #ifndef _LIBCPP_CXX03_LANG
40 template <class _Tp, class _Compare>
41 _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Tp, _Tp>
42 minmax(initializer_list<_Tp> __t, _Compare __comp) {
43 static_assert(__is_callable<_Compare, _Tp, _Tp>::value, "The comparator has to be callable");
44 __identity __proj;
45 auto __ret = std::__minmax_element_impl(__t.begin(), __t.end(), __comp, __proj);
46 return pair<_Tp, _Tp>(*__ret.first, *__ret.second);
49 template <class _Tp>
50 _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Tp, _Tp>
51 minmax(initializer_list<_Tp> __t) {
52 return std::minmax(__t, __less<>());
55 #endif // _LIBCPP_CXX03_LANG
57 _LIBCPP_END_NAMESPACE_STD
59 #endif // _LIBCPP___CXX03___ALGORITHM_MINMAX_H