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_MIN_ELEMENT_H
0010 #define _LIBCPP___CXX03___ALGORITHM_MIN_ELEMENT_H
0011 
0012 #include <__cxx03/__algorithm/comp.h>
0013 #include <__cxx03/__algorithm/comp_ref_type.h>
0014 #include <__cxx03/__config>
0015 #include <__cxx03/__functional/identity.h>
0016 #include <__cxx03/__functional/invoke.h>
0017 #include <__cxx03/__iterator/iterator_traits.h>
0018 #include <__cxx03/__type_traits/is_callable.h>
0019 #include <__cxx03/__utility/move.h>
0020 
0021 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0022 #  pragma GCC system_header
0023 #endif
0024 
0025 _LIBCPP_PUSH_MACROS
0026 #include <__cxx03/__undef_macros>
0027 
0028 _LIBCPP_BEGIN_NAMESPACE_STD
0029 
0030 template <class _Comp, class _Iter, class _Sent, class _Proj>
0031 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Iter
0032 __min_element(_Iter __first, _Sent __last, _Comp __comp, _Proj& __proj) {
0033   if (__first == __last)
0034     return __first;
0035 
0036   _Iter __i = __first;
0037   while (++__i != __last)
0038     if (std::__invoke(__comp, std::__invoke(__proj, *__i), std::__invoke(__proj, *__first)))
0039       __first = __i;
0040 
0041   return __first;
0042 }
0043 
0044 template <class _Comp, class _Iter, class _Sent>
0045 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Iter __min_element(_Iter __first, _Sent __last, _Comp __comp) {
0046   auto __proj = __identity();
0047   return std::__min_element<_Comp>(std::move(__first), std::move(__last), __comp, __proj);
0048 }
0049 
0050 template <class _ForwardIterator, class _Compare>
0051 _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator
0052 min_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) {
0053   static_assert(
0054       __has_forward_iterator_category<_ForwardIterator>::value, "std::min_element requires a ForwardIterator");
0055   static_assert(
0056       __is_callable<_Compare, decltype(*__first), decltype(*__first)>::value, "The comparator has to be callable");
0057 
0058   return std::__min_element<__comp_ref_type<_Compare> >(std::move(__first), std::move(__last), __comp);
0059 }
0060 
0061 template <class _ForwardIterator>
0062 _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator
0063 min_element(_ForwardIterator __first, _ForwardIterator __last) {
0064   return std::min_element(__first, __last, __less<>());
0065 }
0066 
0067 _LIBCPP_END_NAMESPACE_STD
0068 
0069 _LIBCPP_POP_MACROS
0070 
0071 #endif // _LIBCPP___CXX03___ALGORITHM_MIN_ELEMENT_H