1169689Skan//===----------------------------------------------------------------------===//
2132718Skan//
3132718Skan// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4132718Skan// See https://llvm.org/LICENSE.txt for license information.
5132718Skan// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6132718Skan//
7132718Skan//===----------------------------------------------------------------------===//
8132718Skan
9132718Skan#ifndef _LIBCPP___ALGORITHM_MIN_H
10132718Skan#define _LIBCPP___ALGORITHM_MIN_H
11132718Skan
12132718Skan#include <__algorithm/comp.h>
13132718Skan#include <__algorithm/comp_ref_type.h>
14132718Skan#include <__algorithm/min_element.h>
15132718Skan#include <__config>
16132718Skan#include <initializer_list>
17132718Skan
18132718Skan#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19132718Skan#  pragma GCC system_header
20169689Skan#endif
21132718Skan
22132718Skan_LIBCPP_PUSH_MACROS
23132718Skan#include <__undef_macros>
24132718Skan
25132718Skan_LIBCPP_BEGIN_NAMESPACE_STD
26132718Skan
27132718Skantemplate <class _Tp, class _Compare>
28132718Skan_LIBCPP_NODISCARD_EXT inline
29132718Skan_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
30132718Skanconst _Tp&
31132718Skanmin(const _Tp& __a, const _Tp& __b, _Compare __comp)
32132718Skan{
33132718Skan    return __comp(__b, __a) ? __b : __a;
34132718Skan}
35132718Skan
36132718Skantemplate <class _Tp>
37132718Skan_LIBCPP_NODISCARD_EXT inline
38132718Skan_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
39132718Skanconst _Tp&
40132718Skanmin(const _Tp& __a, const _Tp& __b)
41132718Skan{
42169689Skan    return _VSTD::min(__a, __b, __less<_Tp>());
43132718Skan}
44132718Skan
45132718Skan#ifndef _LIBCPP_CXX03_LANG
46132718Skan
47132718Skantemplate<class _Tp, class _Compare>
48132718Skan_LIBCPP_NODISCARD_EXT inline
49132718Skan_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
50132718Skan_Tp
51132718Skanmin(initializer_list<_Tp> __t, _Compare __comp)
52132718Skan{
53132718Skan    return *_VSTD::__min_element<__comp_ref_type<_Compare> >(__t.begin(), __t.end(), __comp);
54132718Skan}
55132718Skan
56132718Skantemplate<class _Tp>
57132718Skan_LIBCPP_NODISCARD_EXT inline
58132718Skan_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
59132718Skan_Tp
60132718Skanmin(initializer_list<_Tp> __t)
61132718Skan{
62132718Skan    return *_VSTD::min_element(__t.begin(), __t.end(), __less<_Tp>());
63132718Skan}
64132718Skan
65132718Skan#endif // _LIBCPP_CXX03_LANG
66132718Skan
67132718Skan_LIBCPP_END_NAMESPACE_STD
68132718Skan
69132718Skan_LIBCPP_POP_MACROS
70132718Skan
71132718Skan#endif // _LIBCPP___ALGORITHM_MIN_H
72132718Skan