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
19
20namespace 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// parasoft-begin-suppress AUTOSAR-A2_10_1-a "False positive: identifiers 'begin' and 'end' do not hide anything"
44template <
45 typename InputIterator,
46 typename OutputIterator,
51constexpr auto move(
52 InputIterator begin,
53 InputIterator end,
54 OutputIterator result
55 ) noexcept(noexcept(*result = std::move(*begin)) && //
58 -> OutputIterator {
59 while (begin != end) {
60 // parasoft-begin-suppress AUTOSAR-A18_9_3-a-2 "Generic function; const or not is specified by user"
61 *result = std::move(*begin);
62 // parasoft-end-suppress AUTOSAR-A18_9_3-a-2
63 // parasoft-begin-suppress AUTOSAR-M5_0_15-a-2 "This is an iterator type, so incrementing is OK"
64 ++begin;
65 ++result;
66 // parasoft-end-suppress AUTOSAR-M5_0_15-a-2
67 }
68 return result;
69}
70// parasoft-end-suppress AUTOSAR-A2_10_1-a
71
72/// @brief Move elements from a source range to a destination range. Implements @c std::move
73///
74/// For each element @c e in the half-open range @c [begin,end) writes @c std::move(e) to @c *result and increments @c
75/// result.
76///
77/// This overload is to generate an error for the case that the elements from the source cannot be assigned to the
78/// destination
79///
80/// @tparam InputIterator The type of the iterators denoting the input range.
81/// @tparam OutputIterator The type of the iterator for the output range
82/// @param begin The start of the source range
83/// @param end The end of the source range
84/// @param result The start of the destination range
85/// @return An @c OutputIterator equivalent to the final value of @c result
86/// @pre @c InputIterator must satisfy the input iterator requirements.
87/// @pre @c [begin,end) must be a valid range.
88/// @pre @c OutputIterator must satisfy the output iterator requirements.
89/// @pre @c result must be a valid iterator for an output range that can be written to at least as many times as there
90/// are elements in the input range.
91/// @pre The value types of the input and output range must be compatible such that @c *result=std::move(*begin) is
92/// well-formed.
93/// @throws Any exception thrown by the iteration or move-assignment operations
94template <
95 typename InputIterator,
96 typename OutputIterator,
101// parasoft-begin-suppress AUTOSAR-A2_10_1-a "False positive: identifiers 'begin' and 'end' do not hide anything"
102auto move(InputIterator begin, InputIterator end, OutputIterator result) -> OutputIterator {
103 ignore = begin;
104 ignore = end;
105 constexpr bool
107 static_assert(can_move_assign_via_iterators, "Must be able to move-assign to output from input");
108 return result;
109}
110// parasoft-end-suppress AUTOSAR-A2_10_1-a
111
112// parasoft-end-suppress AUTOSAR-M3_3_2-a-2
113
114} // namespace std
115
116#endif // INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_MOVE_ALGORITHM_HPP_
Public export header for the constraints subpackage.
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 bool has_nothrow_basic_input_iterator_operations_v
Internal type trait to check if a type supports the necessary input iterator operations without throw...
constexpr bool is_indirectly_move_assignable_v
Internal type trait to check if the values from an input iterator can be move-assigned to the destina...
constexpr bool has_nothrow_basic_output_iterator_operations_v
Internal type trait to check if a type supports the necessary output iterator operations without thro...
STL namespace.
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
constexpr auto end(Element(&array)[Size]) noexcept -> Element *
Obtain a pointer to the one-past-the-end element of the array.
Definition end.hpp:28
static constexpr auto const & ignore
An object to which anything can be assigned, which ignores the assigned value.
Definition ignore.hpp:72
constexpr auto begin(Element(&array)[Size]) noexcept -> Element *
Obtain a pointer to the first element of the array.
Definition begin.hpp:28