Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
lower_bound.hpp
Go to the documentation of this file.
1
// Copyright 2026, Toyota Motor Corporation
2
//
3
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
5
#
ifndef
INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_LOWER_BOUND_HPP_
6
#
define
INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_LOWER_BOUND_HPP_
7
8
#
include
"arene/base/algorithm/detail/functional.hpp"
9
#
include
"arene/base/algorithm/detail/traits.hpp"
10
#
include
"arene/base/constraints.hpp"
11
#
include
"arene/base/functional/bind_back.hpp"
12
#
include
"arene/base/type_traits/is_binary_predicate.hpp"
13
#
include
"arene/base/type_traits/iterator_category_traits.hpp"
14
#
include
"stdlib/include/stdlib_detail/enable_if.hpp"
15
#
include
"stdlib/include/stdlib_detail/internal_partition_point.hpp"
16
#
include
"stdlib/include/stdlib_detail/move.hpp"
17
18
// parasoft-begin-suppress CERT_CPP-DCL58-a-2 "Part of a standard library implementation"
19
// parasoft-begin-suppress AUTOSAR-A17_6_1-a-2 "Part of a standard library implementation"
20
21
// IWYU pragma: private, include <algorithm>
22
// IWYU pragma: friend "stdlib_detail/.*"
23
24
namespace
std
{
25
26
// parasoft-begin-suppress AUTOSAR-M3_3_2-a "False positive: inline function used in multiple translation units"
27
28
/// @brief returns an iterator to the first element not less than the given value
29
/// @tparam ForwardIterator iterator type
30
/// @tparam T value type to compare against
31
/// @tparam Compare binary predicate type
32
/// @param first beginning of the partitioned range of elements
33
/// @param last end of the partitioned range of elements
34
/// @param value value to compare elements to
35
/// @param comp binary predicate which returns @c true if the first argument is ordered before the second
36
///
37
/// @pre @c ForwardIterator must satisfy the forward iterator requirements.
38
/// @pre <tt>[begin, end)</tt> must be a valid range.
39
/// @pre The expression <tt>comp(e, value)</tt> must be convertible to @c bool
40
/// for every argument @c e of type @c RT, where @c RT is the reference type
41
/// of @c ForwardIterator, regardless of value category, and must not modify
42
/// @c e or @c value.
43
/// @pre The elements @c e of <tt>[begin, end)</tt> must be partitioned with
44
/// respect to the expression <tt>comp(e, value)</tt>.
45
///
46
/// @return iterator to the first element of the range <tt>[first, last)</tt>
47
/// not ordered before @c value, or @c last if no such element is found.
48
///
49
/// @note Complexity
50
/// Given N as <tt>std::distance(first, last)</tt>, at most <tt>log2(N) +
51
/// O(1)</tt> applications of the comparator @c comp.
52
///
53
template
<
54
class
ForwardIterator
,
55
class
T
,
56
class
Compare
,
57
arene
::
base
::
constraints
<
58
std
::
enable_if_t
<
arene
::
base
::
is_forward_iterator_v
<
ForwardIterator
>>,
59
std
::
enable_if_t
<
arene
::
base
::
is_binary_predicate_v
<
60
Compare
&,
61
arene
::
base
::
algorithm_detail
::
iter_reference_t
<
ForwardIterator
>,
62
T
const
&>>> =
nullptr
>
63
constexpr
auto
lower_bound
(
ForwardIterator
first
,
ForwardIterator
last
,
T
const
&
value
,
Compare
comp
)
noexcept
(
64
noexcept
(
std
::
internal
::
partition_point
(
65
std
::
move
(
first
),
66
std
::
move
(
last
),
67
arene
::
base
::
bind_back_detail
::
bind_back_t
<
Compare
,
T
const
&>(
comp
,
value
)
68
))
69
) ->
ForwardIterator
{
70
return
std
::
internal
::
partition_point
(
71
std
::
move
(
first
),
72
std
::
move
(
last
),
73
arene
::
base
::
bind_back_detail
::
bind_back_t
<
Compare
,
T
const
&>(
comp
,
value
)
74
);
75
}
76
77
/// @brief returns an iterator to the first element not less than the given value
78
/// @tparam ForwardIterator iterator type
79
/// @tparam T value type to compare against
80
/// @tparam Compare binary predicate type
81
/// @param first beginning of the partitioned range of elements
82
/// @param last end of the partitioned range of elements
83
/// @param value value to compare elements to
84
///
85
/// @pre @c ForwardIterator must satisfy the forward iterator requirements.
86
/// @pre <tt>[begin, end)</tt> must be a valid range.
87
/// @pre The expression <tt>e < value</tt> must be convertible to @c bool
88
/// for every argument @c e of type @c RT, where @c RT is the reference type
89
/// of @c ForwardIterator, regardless of value category, and must not modify
90
/// @c e or @c value.
91
/// @pre The elements @c e of <tt>[begin, end)</tt> must be partitioned with
92
/// respect to the expression <tt>e < value</tt>.
93
///
94
/// @return iterator to the first element of the range <tt>[first, last)</tt>
95
/// not ordered before @c value, or @c last if no such element is found.
96
///
97
/// @note Complexity
98
/// Given N as <tt>std::distance(first, last)</tt>, at most <tt>log2(N) +
99
/// O(1)</tt> comparisons with @c value using @c operator<.
100
///
101
template
<
102
class
ForwardIterator
,
103
class
T
,
104
arene
::
base
::
constraints
<
105
std
::
enable_if_t
<
arene
::
base
::
is_forward_iterator_v
<
ForwardIterator
>>,
106
std
::
enable_if_t
<
arene
::
base
::
is_binary_predicate_v
<
107
decltype
(
arene
::
base
::
algorithm_detail
::
operator_less
)&,
108
arene
::
base
::
algorithm_detail
::
iter_reference_t
<
ForwardIterator
>,
109
T
const
&>>> =
nullptr
>
110
constexpr
auto
lower_bound
(
ForwardIterator
first
,
ForwardIterator
last
,
T
const
&
value
)
noexcept
(
111
noexcept
(
std
::
lower_bound
(
std
::
move
(
first
),
std
::
move
(
last
),
value
,
arene
::
base
::
algorithm_detail
::
operator_less
))
112
) ->
ForwardIterator
{
113
return
std
::
lower_bound
(
std
::
move
(
first
),
std
::
move
(
last
),
value
,
arene
::
base
::
algorithm_detail
::
operator_less
);
114
}
115
116
// parasoft-end-suppress AUTOSAR-M3_3_2-a
117
118
}
// namespace std
119
120
#
endif
// INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_LOWER_BOUND_HPP_
std::hash<::arene::base::result< void, E > >::operator()
constexpr auto operator()(::arene::base::result< void, E > const &value) const noexcept(noexcept(hash< E >{}(std::declval< E const & >()))) -> std::size_t
Calculate the hash of a result.
Definition
result.hpp:1827
stdlib
include
stdlib_detail
lower_bound.hpp
Generated by
1.13.2