1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef _LIBCPP___ALGORITHM_MIN_H
10 #define _LIBCPP___ALGORITHM_MIN_H
12 #include <__algorithm/comp.h>
13 #include <__algorithm/comp_ref_type.h>
14 #include <__algorithm/min_element.h>
16 #include <initializer_list>
18 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19 #pragma GCC system_header
23 #include <__undef_macros>
25 _LIBCPP_BEGIN_NAMESPACE_STD
27 template <class _Tp, class _Compare>
28 _LIBCPP_NODISCARD_EXT inline
29 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
31 min(const _Tp& __a, const _Tp& __b, _Compare __comp)
33 return __comp(__b, __a) ? __b : __a;
37 _LIBCPP_NODISCARD_EXT inline
38 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
40 min(const _Tp& __a, const _Tp& __b)
42 return _VSTD::min(__a, __b, __less<_Tp>());
45 #ifndef _LIBCPP_CXX03_LANG
47 template<class _Tp, class _Compare>
48 _LIBCPP_NODISCARD_EXT inline
49 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
51 min(initializer_list<_Tp> __t, _Compare __comp)
53 typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
54 return *_VSTD::__min_element<_Comp_ref>(__t.begin(), __t.end(), __comp);
58 _LIBCPP_NODISCARD_EXT inline
59 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
61 min(initializer_list<_Tp> __t)
63 return *_VSTD::min_element(__t.begin(), __t.end(), __less<_Tp>());
66 #endif // _LIBCPP_CXX03_LANG
68 _LIBCPP_END_NAMESPACE_STD
72 #endif // _LIBCPP___ALGORITHM_MIN_H