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_MAX_ELEMENT_H
0010 #define _LIBCPP___CXX03___ALGORITHM_MAX_ELEMENT_H
0011 
0012 #include <__cxx03/__algorithm/comp.h>
0013 #include <__cxx03/__algorithm/comp_ref_type.h>
0014 #include <__cxx03/__config>
0015 #include <__cxx03/__iterator/iterator_traits.h>
0016 
0017 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0018 #  pragma GCC system_header
0019 #endif
0020 
0021 _LIBCPP_BEGIN_NAMESPACE_STD
0022 
0023 template <class _Compare, class _ForwardIterator>
0024 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator
0025 __max_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) {
0026   static_assert(
0027       __has_forward_iterator_category<_ForwardIterator>::value, "std::max_element requires a ForwardIterator");
0028   if (__first != __last) {
0029     _ForwardIterator __i = __first;
0030     while (++__i != __last)
0031       if (__comp(*__first, *__i))
0032         __first = __i;
0033   }
0034   return __first;
0035 }
0036 
0037 template <class _ForwardIterator, class _Compare>
0038 _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator
0039 max_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) {
0040   return std::__max_element<__comp_ref_type<_Compare> >(__first, __last, __comp);
0041 }
0042 
0043 template <class _ForwardIterator>
0044 _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator
0045 max_element(_ForwardIterator __first, _ForwardIterator __last) {
0046   return std::max_element(__first, __last, __less<>());
0047 }
0048 
0049 _LIBCPP_END_NAMESPACE_STD
0050 
0051 #endif // _LIBCPP___CXX03___ALGORITHM_MAX_ELEMENT_H