max.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. #ifndef _LIBCPP___ALGORITHM_MAX_H
  9. #define _LIBCPP___ALGORITHM_MAX_H
  10. #include <__algorithm/comp.h>
  11. #include <__algorithm/comp_ref_type.h>
  12. #include <__algorithm/max_element.h>
  13. #include <__config>
  14. #include <initializer_list>
  15. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  16. # pragma GCC system_header
  17. #endif
  18. _LIBCPP_PUSH_MACROS
  19. #include <__undef_macros>
  20. _LIBCPP_BEGIN_NAMESPACE_STD
  21. template <class _Tp, class _Compare>
  22. _LIBCPP_NODISCARD_EXT inline
  23. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
  24. const _Tp&
  25. max(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b, _Compare __comp)
  26. {
  27. return __comp(__a, __b) ? __b : __a;
  28. }
  29. template <class _Tp>
  30. _LIBCPP_NODISCARD_EXT inline
  31. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
  32. const _Tp&
  33. max(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b)
  34. {
  35. return _VSTD::max(__a, __b, __less<>());
  36. }
  37. #ifndef _LIBCPP_CXX03_LANG
  38. template<class _Tp, class _Compare>
  39. _LIBCPP_NODISCARD_EXT inline
  40. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
  41. _Tp
  42. max(initializer_list<_Tp> __t, _Compare __comp)
  43. {
  44. return *_VSTD::__max_element<__comp_ref_type<_Compare> >(__t.begin(), __t.end(), __comp);
  45. }
  46. template<class _Tp>
  47. _LIBCPP_NODISCARD_EXT inline
  48. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
  49. _Tp
  50. max(initializer_list<_Tp> __t)
  51. {
  52. return *_VSTD::max_element(__t.begin(), __t.end(), __less<>());
  53. }
  54. #endif // _LIBCPP_CXX03_LANG
  55. _LIBCPP_END_NAMESPACE_STD
  56. _LIBCPP_POP_MACROS
  57. #endif // _LIBCPP___ALGORITHM_MAX_H