Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
internal_partition_point.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_INTERNAL_PARTITION_POINT_HPP_
6
#
define
INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_INTERNAL_PARTITION_POINT_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/iterator/distance.hpp"
12
#
include
"arene/base/iterator/next.hpp"
13
#
include
"arene/base/type_traits/is_predicate.hpp"
14
#
include
"arene/base/type_traits/iterator_category_traits.hpp"
15
#
include
"stdlib/include/stdlib_detail/enable_if.hpp"
16
#
include
"stdlib/include/stdlib_detail/is_move_assignable.hpp"
17
#
include
"stdlib/include/stdlib_detail/is_move_constructible.hpp"
18
19
// parasoft-begin-suppress CERT_CPP-DCL58-a-2 "Part of a standard library implementation"
20
// parasoft-begin-suppress AUTOSAR-A17_6_1-a-2 "Part of a standard library implementation"
21
22
// IWYU pragma: friend "stdlib_detail/.*"
23
24
namespace
std
{
25
namespace
internal
{
26
27
// parasoft-begin-suppress AUTOSAR-M3_3_2-a "False positive: inline function used in multiple translation units"
28
29
/// @brief locates the partition point of a range partitioned with respect to an unary predicate
30
/// @tparam ForwardIterator iterator type
31
/// @tparam UnaryPred unary predicate type
32
/// @param first beginning of the partitioned range of elements
33
/// @param last end of the partitioned range of elements
34
/// @param pred predicate specifying the partition
35
///
36
/// @return iterator past the end of the first partition within <tt>[first,
37
/// last)</tt> or @c last if all elements satisfy @c pred.
38
///
39
template
<
40
class
ForwardIterator
,
41
class
UnaryPred
,
42
arene
::
base
::
constraints
<
43
std
::
enable_if_t
<
arene
::
base
::
is_forward_iterator_v
<
ForwardIterator
>>,
44
std
::
enable_if_t
<
arene
::
base
::
is_predicate_v
<
45
UnaryPred
&,
46
arene
::
base
::
algorithm_detail
::
iter_reference_t
<
ForwardIterator
>>>> =
nullptr
>
47
constexpr
auto
partition_point
(
ForwardIterator
first
,
ForwardIterator
last
,
UnaryPred
pred
)
noexcept
(
48
std
::
is_nothrow_move_constructible_v
<
ForwardIterator
>
and
//
49
std
::
is_nothrow_move_assignable_v
<
ForwardIterator
>
and
//
50
noexcept
(
arene
::
base
::
distance
(
first
,
last
))
and
//
51
noexcept
(
arene
::
base
::
next
(
first
))
and
//
52
noexcept
(
pred
(*
first
))
53
) ->
ForwardIterator
{
54
using
difference_type
=
arene
::
base
::
algorithm_detail
::
iter_difference_t
<
ForwardIterator
>;
55
constexpr
difference_type
two
{2};
56
57
using
arene
::
base
::
distance
;
58
using
arene
::
base
::
next
;
59
60
auto
length
=
distance
(
first
,
last
);
61
while
(
length
>
difference_type
{}) {
62
auto
const
half
=
length
/
two
;
63
auto
const
middle
=
next
(
first
,
half
);
64
65
if
(
pred
(*
middle
)) {
66
first
=
next
(
middle
);
67
length
-= (
half
+
difference_type
{1});
68
}
else
{
69
length
=
half
;
70
}
71
}
72
73
return
first
;
74
}
75
76
// parasoft-end-suppress AUTOSAR-M3_3_2-a
77
78
}
// namespace internal
79
}
// namespace std
80
81
#
endif
// INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_INTERNAL_PARTITION_POINT_HPP_
std::internal
Definition
internal_named_requirements.hpp:19
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
internal_partition_point.hpp
Generated by
1.13.2