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 //===----------------------------------------------------------------------===// 8 9 #ifndef _LIBCPP___ALGORITHM_MAX_H 10 #define _LIBCPP___ALGORITHM_MAX_H 11 12 #include <__algorithm/comp.h> 13 #include <__algorithm/comp_ref_type.h> 14 #include <__algorithm/max_element.h> 15 #include <__config> 16 #include <initializer_list> 17 18 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 19 # pragma GCC system_header 20 # pragma clang include_instead(<algorithm>) 21 #endif 22 23 _LIBCPP_PUSH_MACROS 24 #include <__undef_macros> 25 26 _LIBCPP_BEGIN_NAMESPACE_STD 27 28 template <class _Tp, class _Compare> 29 _LIBCPP_NODISCARD_EXT inline 30 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 31 const _Tp& 32 max(const _Tp& __a, const _Tp& __b, _Compare __comp) 33 { 34 return __comp(__a, __b) ? __b : __a; 35 } 36 37 template <class _Tp> 38 _LIBCPP_NODISCARD_EXT inline 39 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 40 const _Tp& 41 max(const _Tp& __a, const _Tp& __b) 42 { 43 return _VSTD::max(__a, __b, __less<_Tp>()); 44 } 45 46 #ifndef _LIBCPP_CXX03_LANG 47 48 template<class _Tp, class _Compare> 49 _LIBCPP_NODISCARD_EXT inline 50 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 51 _Tp 52 max(initializer_list<_Tp> __t, _Compare __comp) 53 { 54 typedef typename __comp_ref_type<_Compare>::type _Comp_ref; 55 return *_VSTD::__max_element<_Comp_ref>(__t.begin(), __t.end(), __comp); 56 } 57 58 template<class _Tp> 59 _LIBCPP_NODISCARD_EXT inline 60 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 61 _Tp 62 max(initializer_list<_Tp> __t) 63 { 64 return *_VSTD::max_element(__t.begin(), __t.end(), __less<_Tp>()); 65 } 66 67 #endif // _LIBCPP_CXX03_LANG 68 69 _LIBCPP_END_NAMESPACE_STD 70 71 _LIBCPP_POP_MACROS 72 73 #endif // _LIBCPP___ALGORITHM_MAX_H 74