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_RANGES_MINMAX_ELEMENT_H
10#define _LIBCPP___ALGORITHM_RANGES_MINMAX_ELEMENT_H
11
12#include <__algorithm/min_max_result.h>
13#include <__algorithm/minmax_element.h>
14#include <__config>
15#include <__functional/identity.h>
16#include <__functional/invoke.h>
17#include <__functional/ranges_operations.h>
18#include <__iterator/concepts.h>
19#include <__iterator/projected.h>
20#include <__ranges/access.h>
21#include <__ranges/concepts.h>
22#include <__ranges/dangling.h>
23#include <__utility/forward.h>
24#include <__utility/move.h>
25#include <__utility/pair.h>
26#include <type_traits>
27
28#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
29#  pragma GCC system_header
30#endif
31
32#if _LIBCPP_STD_VER > 17
33
34_LIBCPP_BEGIN_NAMESPACE_STD
35
36namespace ranges {
37
38template <class _T1>
39using minmax_element_result = min_max_result<_T1>;
40
41namespace __minmax_element {
42struct __fn {
43  template <forward_iterator _Ip, sentinel_for<_Ip> _Sp, class _Proj = identity,
44            indirect_strict_weak_order<projected<_Ip, _Proj>> _Comp = ranges::less>
45  _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr
46  ranges::minmax_element_result<_Ip> operator()(_Ip __first, _Sp __last, _Comp __comp = {}, _Proj __proj = {}) const {
47    auto __ret = std::__minmax_element_impl(std::move(__first), std::move(__last), __comp, __proj);
48    return {__ret.first, __ret.second};
49  }
50
51  template <forward_range _Rp, class _Proj = identity,
52            indirect_strict_weak_order<projected<iterator_t<_Rp>, _Proj>> _Comp = ranges::less>
53  _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr
54  ranges::minmax_element_result<borrowed_iterator_t<_Rp>>
55  operator()(_Rp&& __r, _Comp __comp = {}, _Proj __proj = {}) const {
56    auto __ret = std::__minmax_element_impl(ranges::begin(__r), ranges::end(__r), __comp, __proj);
57    return {__ret.first, __ret.second};
58  }
59};
60} // namespace __minmax_element
61
62inline namespace __cpo {
63  inline constexpr auto minmax_element = __minmax_element::__fn{};
64} // namespace __cpo
65
66} // namespace ranges
67
68_LIBCPP_END_NAMESPACE_STD
69
70#endif // _LIBCPP_STD_VER > 17
71
72#endif // _LIBCPP___ALGORITHM_RANGES_MINMAX_H
73