59 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef _LIBCPP___ALGORITHM_MAX_H10#define _LIBCPP___ALGORITHM_MAX_H11 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_header20#endif21 22_LIBCPP_PUSH_MACROS23#include <__undef_macros>24 25_LIBCPP_BEGIN_NAMESPACE_STD26 27template <class _Tp, class _Compare>28[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Tp&29max(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b, _Compare __comp) {30 return __comp(__a, __b) ? __b : __a;31}32 33template <class _Tp>34[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Tp&35max(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b) {36 return std::max(__a, __b, __less<>());37}38 39#ifndef _LIBCPP_CXX03_LANG40 41template <class _Tp, class _Compare>42[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp43max(initializer_list<_Tp> __t, _Compare __comp) {44 return *std::__max_element<__comp_ref_type<_Compare> >(__t.begin(), __t.end(), __comp);45}46 47template <class _Tp>48[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp max(initializer_list<_Tp> __t) {49 return *std::max_element(__t.begin(), __t.end(), __less<>());50}51 52#endif // _LIBCPP_CXX03_LANG53 54_LIBCPP_END_NAMESPACE_STD55 56_LIBCPP_POP_MACROS57 58#endif // _LIBCPP___ALGORITHM_MAX_H59