Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
move.hpp
Go to the documentation of this file.
1// Copyright 2024, Toyota Motor Corporation
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
5#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_ALGORITHM_MOVE_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_ALGORITHM_MOVE_HPP_
7
8// IWYU pragma: private, include "arene/base/algorithm.hpp"
9// IWYU pragma: friend "(arene/base(?!/tests)|stdlib/include/stdlib_detail)/.*"
10
11// parasoft-begin-suppress AUTOSAR-A16_2_2-a-2 "Arene Base aggregate headers permitted by A16-2-2 Permit #1"
13#include "arene/base/stdlib_choice/declval.hpp"
14#include "arene/base/stdlib_choice/enable_if.hpp"
15#include "arene/base/stdlib_choice/is_assignable.hpp"
16#include "arene/base/stdlib_choice/iterator_traits.hpp"
17#include "arene/base/stdlib_choice/move.hpp"
20// parasoft-end-suppress AUTOSAR-A16_2_2-a-2
21
22namespace arene {
23namespace base {
24
25// parasoft-begin-suppress AUTOSAR-M3_3_2-a-2 "False positive: inline function used in multiple translation units"
26/// @brief Moves the elements in the range <tt>[first, last)</tt>, to another
27/// range beginning at @c output, starting from @c first and proceeding to
28/// <tt>last - 1</tt>. After this operation the elements in the moved-from range
29/// will still contain valid values of the appropriate type, but not necessarily
30/// the same values as before the move.
31/// @tparam InIterator The type of the Iterator for the range to take items from
32/// @tparam OutIterator The type of the Iterator for the range to put items into
33/// @param first Start of the range to take items from
34/// @param last End (exclusive) of the range to take items from
35/// @param output Start of the range to put items into
36/// @return OutIterator for the element past the last moved item
37template <
38 class InIterator,
39 class OutIterator,
43 std::enable_if_t<std::is_assignable<
44 decltype(*std::declval<OutIterator>()),
45 typename std::iterator_traits<InIterator>::value_type&&>::value>> = nullptr>
46constexpr auto move(
47 InIterator first,
48 InIterator last, // CODEQLFP(DCL51-CPP) CODEQLFP(A15-4-4)
49 OutIterator output
50) //
51 noexcept(
52 noexcept(*first++) && noexcept(output++) && // CODEQLFP(EXP52-CPP) CODEQLFP(A5-2-6)
53 noexcept(first != last) && // CODEQLFP(A5-2-6)
55 decltype(*std::declval<OutIterator>()),
57 ) -> OutIterator { // CODEQLFP(M5-3-1)
58 for (auto& element : arene::base::make_subrange(first, last)) { // CODEQLFP(A7-1-1) CODEQLFP(A7-1-2)
59 // parasoft-begin-suppress AUTOSAR-A18_9_3-a-2 "False Positive: Generic code, 'element' is not explicitly const"
60 *output++ = std::move(element); // CODEQLFP(CTR55-CPP) CODEQLFP(A4-7-1) CODEQLFP(M5-2-10)
61 // parasoft-end-suppress AUTOSAR-A18_9_3-a-2
62 } // CODEQLFP(A5-0-2)
63 return output;
64}
65// parasoft-end-suppress AUTOSAR-M3_3_2-a-2
66
67} // namespace base
68} // namespace arene
69
70#endif // INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_ALGORITHM_MOVE_HPP_
Type trait to detect if an instance of To is assignable to from arguments of From without throwing.
Definition is_assignable.hpp:78
provides a uniform interface to the properties of an iterator
Definition iterator_traits.hpp:90
Definition accumulate.hpp:37
constexpr auto move(InIterator first, InIterator last, OutIterator output) noexcept(noexcept(*first++) &&noexcept(output++) &&//CODEQLFP(EXP52-CPP) CODEQLFP(A5-2-6) noexcept(first !=last) &&//CODEQLFP(A5-2-6) std::is_nothrow_assignable<, typename std::iterator_traits< InIterator >::value_type >::value) -> OutIterator
Moves the elements in the range [first, last), to another range beginning at output,...
Definition move.hpp:46
constexpr auto make_subrange(Iterator iterator, Sentinel sentinel) noexcept(std::is_nothrow_move_constructible< Iterator >::value &&//std::is_nothrow_move_constructible< Sentinel >::value) -> make_subrange_detail::iterator_range< Iterator, Sentinel >
Combine an iterator and sentinel into a range type that can be used with range-based for loops.
Definition make_subrange.hpp:98
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
Definition accumulate.hpp:36
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
auto declval() noexcept -> T &&
A dummy function that is declared but not defined, with a user-specified return type,...