Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
move_algorithm.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_MOVE_ALGORITHM_HPP_
6
#
define
INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_MOVE_ALGORITHM_HPP_
7
8
// parasoft-begin-suppress CERT_CPP-DCL58-a-2 "Part of a standard library implementation"
9
// parasoft-begin-suppress AUTOSAR-A17_6_1-a-2 "Part of a standard library implementation"
10
11
// IWYU pragma: private, include <algorithm>
12
// IWYU pragma: friend "stdlib_detail/.*"
13
14
#
include
"arene/base/constraints.hpp"
15
#
include
"stdlib/include/stdlib_detail/enable_if.hpp"
16
#
include
"stdlib/include/stdlib_detail/ignore.hpp"
17
#
include
"stdlib/include/stdlib_detail/iterator_concepts.hpp"
18
#
include
"stdlib/include/stdlib_detail/move.hpp"
19
20
namespace
std
{
21
22
// parasoft-begin-suppress AUTOSAR-M3_3_2-a-2 "False positive: inline function used in multiple translation units"
23
24
/// @brief Move elements from a source range to a destination range. Implements @c std::move
25
///
26
/// For each element @c e in the half-open range @c [begin,end) in order, writes @c std::move(e) to @c *result and
27
/// increments @c result
28
///
29
/// @tparam InputIterator The type of the iterators denoting the input range.
30
/// @tparam OutputIterator The type of the iterator for the output range
31
/// @param begin The start of the source range
32
/// @param end The end of the source range
33
/// @param result The start of the destination range
34
/// @return An @c OutputIterator equivalent to the final value of @c result
35
/// @pre @c InputIterator must satisfy the input iterator requirements.
36
/// @pre @c [begin,end) must be a valid range.
37
/// @pre @c OutputIterator must satisfy the output iterator requirements.
38
/// @pre @c result must be a valid iterator for an output range that can be written to at least as many times as there
39
/// are elements in the input range.
40
/// @pre The value types of the input and output range must be compatible such that @c *result=std::move(*begin) is
41
/// well-formed.
42
/// @throws Any exception thrown by the iteration or move-assignment operations
43
template
<
44
typename
InputIterator
,
45
typename
OutputIterator
,
46
arene
::
base
::
constraints
<
47
enable_if_t
<
internal
::
has_basic_input_iterator_operations_v
<
InputIterator
>>,
48
enable_if_t
<
internal
::
has_basic_output_iterator_operations_v
<
OutputIterator
>>,
49
enable_if_t
<
internal
::
is_indirectly_move_assignable_v
<
InputIterator
,
OutputIterator
>>> =
nullptr
>
50
constexpr
auto
move
(
51
InputIterator
begin
,
52
InputIterator
end
,
53
OutputIterator
result
54
)
noexcept
(
noexcept
(*
result
=
std
::
move
(*
begin
)) &&
//
55
internal
::
has_nothrow_basic_input_iterator_operations_v
<
InputIterator
> &&
//
56
internal
::
has_nothrow_basic_output_iterator_operations_v
<
OutputIterator
>)
57
->
OutputIterator
{
58
while
(
begin
!=
end
) {
59
// parasoft-begin-suppress AUTOSAR-A18_9_3-a-2 "Generic function; const or not is specified by user"
60
*
result
=
std
::
move
(*
begin
);
61
// parasoft-end-suppress AUTOSAR-A18_9_3-a-2
62
// parasoft-begin-suppress AUTOSAR-M5_0_15-a-2 "This is an iterator type, so incrementing is OK"
63
++
begin
;
64
++
result
;
65
// parasoft-end-suppress AUTOSAR-M5_0_15-a-2
66
}
67
return
result
;
68
}
69
70
/// @brief Move elements from a source range to a destination range. Implements @c std::move
71
///
72
/// For each element @c e in the half-open range @c [begin,end) writes @c std::move(e) to @c *result and increments @c
73
/// result.
74
///
75
/// This overload is to generate an error for the case that the elements from the source cannot be assigned to the
76
/// destination
77
///
78
/// @tparam InputIterator The type of the iterators denoting the input range.
79
/// @tparam OutputIterator The type of the iterator for the output range
80
/// @param begin The start of the source range
81
/// @param end The end of the source range
82
/// @param result The start of the destination range
83
/// @return An @c OutputIterator equivalent to the final value of @c result
84
/// @pre @c InputIterator must satisfy the input iterator requirements.
85
/// @pre @c [begin,end) must be a valid range.
86
/// @pre @c OutputIterator must satisfy the output iterator requirements.
87
/// @pre @c result must be a valid iterator for an output range that can be written to at least as many times as there
88
/// are elements in the input range.
89
/// @pre The value types of the input and output range must be compatible such that @c *result=std::move(*begin) is
90
/// well-formed.
91
/// @throws Any exception thrown by the iteration or move-assignment operations
92
template
<
93
typename
InputIterator
,
94
typename
OutputIterator
,
95
arene
::
base
::
constraints
<
96
enable_if_t
<
internal
::
has_basic_input_iterator_operations_v
<
InputIterator
>>,
97
enable_if_t
<
internal
::
has_basic_output_iterator_operations_v
<
OutputIterator
>>,
98
enable_if_t
<!
internal
::
is_indirectly_move_assignable_v
<
InputIterator
,
OutputIterator
>>> =
nullptr
>
99
auto
move
(
InputIterator
begin
,
InputIterator
end
,
OutputIterator
result
) ->
OutputIterator
{
100
ignore
=
begin
;
101
ignore
=
end
;
102
constexpr
bool
103
can_move_assign_via_iterators
{
internal
::
is_indirectly_move_assignable_v
<
InputIterator
,
OutputIterator
>};
104
static_assert
(
can_move_assign_via_iterators
,
"Must be able to move-assign to output from input"
);
105
return
result
;
106
}
107
108
// parasoft-end-suppress AUTOSAR-M3_3_2-a-2
109
110
}
// namespace std
111
112
#
endif
// INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_MOVE_ALGORITHM_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
move_algorithm.hpp
Generated by
1.13.2