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/traits.hpp"
11#include "arene/base/functional/detail/operator_less.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
24namespace 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///
53template <
54 class ForwardIterator,
55 class T,
56 class Compare,
60 Compare&,
61 arene::base::algorithm_detail::iter_reference_t<ForwardIterator>,
62 T const&>>> = nullptr>
63constexpr auto lower_bound(ForwardIterator first, ForwardIterator last, T const& value, Compare comp) noexcept(
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 {
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///
101template <
102 class ForwardIterator,
103 class T,
107 decltype(arene::base::functional_detail::operator_less)&,
108 arene::base::algorithm_detail::iter_reference_t<ForwardIterator>,
109 T const&>>> = nullptr>
110constexpr 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::functional_detail::operator_less))
112) -> ForwardIterator {
113 return std::lower_bound(std::move(first), std::move(last), value, arene::base::functional_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_
Public export header for the constraints subpackage.
constexpr bool is_binary_predicate_v
determines if a type satisfies the BinaryPredicate named requirement
typename constraints_impl::constraints< EnableIfs... >::type constraints
Helper used to express template constraints in a consistent way using std::enable_if_t.
Definition constraints.hpp:51
constexpr auto partition_point(ForwardIterator first, ForwardIterator last, UnaryPred pred) noexcept(std::is_nothrow_move_constructible_v< ForwardIterator > and//std::is_nothrow_move_assignable_v< ForwardIterator >and//noexcept(arene::base::distance(first, last)) and//noexcept(arene::base::next(first)) and//noexcept(pred(*first))) -> ForwardIterator
locates the partition point of a range partitioned with respect to an unary predicate
Definition internal_partition_point.hpp:46
STL namespace.
constexpr auto lower_bound(ForwardIterator first, ForwardIterator last, T const &value, Compare comp) noexcept(noexcept(std::internal::partition_point(std::move(first), std::move(last), arene::base::bind_back_detail::bind_back_t< Compare, T const & >(comp, value)))) -> ForwardIterator
returns an iterator to the first element not less than the given value
Definition lower_bound.hpp:63
constexpr Type integral_constant< Type, Value >::value
Out-of-line definition for the value constant.
Definition integral_constant.hpp:64
constexpr auto move(T &&value) noexcept -> remove_reference_t< T > &&
Cast a value to an rvalue.
Definition move.hpp:30
typename enable_if< Condition, Type >::type enable_if_t
Type alias to support constraining templates. Is an alias for the specified type if the Condition is ...
Definition enable_if.hpp:41