xref: /freebsd/contrib/llvm-project/libcxx/include/__algorithm/min.h (revision 82d4dc0621c92e3c05a86013eec35afbdec057a5)
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_MIN_H
10  #define _LIBCPP___ALGORITHM_MIN_H
11  
12  #include <__config>
13  #include <__algorithm/comp.h>
14  #include <__algorithm/min_element.h>
15  #include <initializer_list>
16  
17  #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18  #pragma GCC system_header
19  #endif
20  
21  _LIBCPP_PUSH_MACROS
22  #include <__undef_macros>
23  
24  _LIBCPP_BEGIN_NAMESPACE_STD
25  
26  template <class _Tp, class _Compare>
27  _LIBCPP_NODISCARD_EXT inline
28  _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
29  const _Tp&
30  min(const _Tp& __a, const _Tp& __b, _Compare __comp)
31  {
32      return __comp(__b, __a) ? __b : __a;
33  }
34  
35  template <class _Tp>
36  _LIBCPP_NODISCARD_EXT inline
37  _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
38  const _Tp&
39  min(const _Tp& __a, const _Tp& __b)
40  {
41      return _VSTD::min(__a, __b, __less<_Tp>());
42  }
43  
44  #ifndef _LIBCPP_CXX03_LANG
45  
46  template<class _Tp, class _Compare>
47  _LIBCPP_NODISCARD_EXT inline
48  _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
49  _Tp
50  min(initializer_list<_Tp> __t, _Compare __comp)
51  {
52      return *_VSTD::min_element(__t.begin(), __t.end(), __comp);
53  }
54  
55  template<class _Tp>
56  _LIBCPP_NODISCARD_EXT inline
57  _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
58  _Tp
59  min(initializer_list<_Tp> __t)
60  {
61      return *_VSTD::min_element(__t.begin(), __t.end(), __less<_Tp>());
62  }
63  
64  #endif // _LIBCPP_CXX03_LANG
65  
66  _LIBCPP_END_NAMESPACE_STD
67  
68  _LIBCPP_POP_MACROS
69  
70  #endif // _LIBCPP___ALGORITHM_MIN_H
71