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
13
#
include
"arene/base/constraints/constraints.hpp"
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"
19
#
include
"arene/base/type_traits/iterator_category_traits.hpp"
20
// parasoft-end-suppress AUTOSAR-A16_2_2-a-2
21
22
namespace
arene
{
23
namespace
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
35
template
<
36
class
InIterator
,
37
class
OutIterator
,
38
constraints
<
39
std
::
enable_if_t
<
base
::
is_input_iterator_v
<
InIterator
>>,
40
std
::
enable_if_t
<
base
::
is_output_iterator_v
<
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
45
constexpr
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)
51
std
::
is_nothrow_assignable
<
decltype
(*
std
::
declval
<
OutIterator
>()),
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_
arene::base
Definition
array_exceptions_disabled.cpp:11
arene
Copyright 2026, Toyota Motor Corporation.
Definition
array_exceptions_disabled.cpp:10
arene
base
algorithm
move_backward.hpp
Generated by
1.13.2