Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
move_backward.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_BACKWARD_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_ALGORITHM_MOVE_BACKWARD_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"
12
14#include "arene/base/stdlib_choice/declval.hpp"
15#include "arene/base/stdlib_choice/enable_if.hpp"
16#include "arene/base/stdlib_choice/is_assignable.hpp"
17#include "arene/base/stdlib_choice/iterator_traits.hpp"
18#include "arene/base/stdlib_choice/move.hpp"
20// parasoft-end-suppress AUTOSAR-A16_2_2-a-2
21
22namespace arene {
23namespace base {
24
25/// @brief Moves the elements from the range <tt>[first, last)</tt>, to another
26/// range ending at @c result. The elements are moved in reverse order (the last
27/// element is moved first), but their relative order is preserved.
28/// @tparam InIterator The type of the Iterator for the range to take items from
29/// @tparam OutIterator The type of the Iterator for the range to put items into
30/// @param first Start of the range to take items from
31/// @param last End (exclusive) of the range to take items from
32/// @param result Start of the range to put items into
33/// @return OutIterator for the last moved item
34
35template <
36 class InIterator,
37 class OutIterator,
41 std::enable_if_t<std::is_assignable<
42 decltype(*std::declval<OutIterator>()),
43 typename std::iterator_traits<InIterator>::value_type&&>::value>> = nullptr>
44// clang-format off
45constexpr auto move_backward( // CODEQLFP(DCL51-CPP) CODEQLFP(A15-4-4)
46 InIterator first, InIterator last, // CODEQLFP(A7-1-1)
47 OutIterator result) noexcept( //
48 noexcept(--result) && noexcept(*result) && // CODEQLFP(EXP52-CPP) CODEQLFP(A5-2-6) CODEQLFP(M5-14-1)
49 noexcept(*last) && noexcept(--last) && // CODEQLFP(EXP52-CPP) CODEQLFP(A5-2-6) CODEQLFP(M5-14-1)
50 noexcept(first != last) && // CODEQLFP(EXP52-CPP) CODEQLFP(A5-2-6) CODEQLFP(M5-14-1)
52 typename std::iterator_traits<InIterator>::value_type>::value) -> OutIterator // CODEQLFP(A5-1-1) CODEQLFP(M5-3-1)
53// clang-format on
54{
55 while (first != last) {
56 // parasoft-begin-suppress AUTOSAR-A18_9_3-a-2 "False Positive: Generic code, moved object is not explicitly const"
57 *--result = std::move(*--last); // CODEQLFP(A4-7-1) CODEQLFP(M5-2-10)
58 // parasoft-end-suppress AUTOSAR-A18_9_3-a-2
59 } // CODEQLFP(A5-0-2)
60 return result;
61}
62
63} // namespace base
64} // namespace arene
65
66#endif // INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_ALGORITHM_MOVE_BACKWARD_HPP_
A sum type which can hold either a value or an error. Similar to std::expected.
Definition result.hpp:104
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_backward(InIterator first, InIterator last, OutIterator result) noexcept(//noexcept(--result) &&noexcept(*result) &&//CODEQLFP(EXP52-CPP) CODEQLFP(A5-2-6) CODEQLFP(M5-14-1) noexcept(*last) &&noexcept(--last) &&//CODEQLFP(EXP52-CPP) CODEQLFP(A5-2-6) CODEQLFP(M5-14-1) noexcept(first !=last) &&//CODEQLFP(EXP52-CPP) CODEQLFP(A5-2-6) CODEQLFP(M5-14-1) std::is_nothrow_assignable<, typename std::iterator_traits< InIterator >::value_type >::value) -> OutIterator
Moves the elements from the range [first, last), to another range ending at result....
Definition move_backward.hpp:45
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,...