Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
swap.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_SWAP_HPP_
6
#
define
INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_SWAP_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 <utility>
12
// IWYU pragma: friend "stdlib_detail/.*"
13
14
#
include
"arene/base/constraints.hpp"
15
#
include
"arene/base/type_traits/is_swappable.hpp"
16
#
include
"stdlib/include/stdlib_detail/cstddef.hpp"
17
#
include
"stdlib/include/stdlib_detail/enable_if.hpp"
18
#
include
"stdlib/include/stdlib_detail/move.hpp"
19
20
namespace
std
{
21
22
// parasoft-begin-suppress AUTOSAR-M3_3_2-a "False positive: inline function used in multiple translation units"
23
24
// parasoft-begin-suppress AUTOSAR-A8_4_8-a "False positive: 'lhs' and 'rhs' are in-out parameters, not output
25
// parameters"
26
27
/// @brief swaps the values of two objects
28
///
29
/// @tparam T type of the objects to swap
30
/// @param lhs object to swap
31
/// @param rhs object to swap
32
template
<
class
T
,
arene
::
base
::
constraints
<
std
::
enable_if_t
<
arene
::
base
::
is_default_swappable_v
<
T
>>> =
nullptr
>
33
constexpr
auto
swap
(
T
&
lhs
,
T
&
rhs
)
noexcept
(
arene
::
base
::
is_nothrow_default_swappable_v
<
T
>) ->
void
{
34
auto
temp
=
std
::
move
(
lhs
);
35
lhs
=
std
::
move
(
rhs
);
36
rhs
=
std
::
move
(
temp
);
37
}
38
39
// parasoft-end-suppress AUTOSAR-A8_4_8-a
40
41
/// @brief swaps the contents of two arrays
42
///
43
/// @tparam T type of the objects in the arrays to swap
44
/// @param lhs array to swap
45
/// @param rhs array to swap
46
template
<
class
T
,
std
::
size_t
N
,
arene
::
base
::
constraints
<
std
::
enable_if_t
<
arene
::
base
::
is_swappable_v
<
T
>>> =
nullptr
>
47
// NOLINTNEXTLINE(hicpp-avoid-c-arrays) explicitly providing c-array support
48
constexpr
auto
swap
(
T
(&
lhs
)[
N
],
T
(&
rhs
)[
N
])
noexcept
(
arene
::
base
::
is_nothrow_swappable_v
<
T
>) ->
void
{
49
for
(
std
::
size_t
idx
{};
idx
<
N
; ++
idx
) {
50
swap
(
lhs
[
idx
],
rhs
[
idx
]);
51
}
52
}
53
54
// parasoft-end-suppress AUTOSAR-M3_3_2-a
55
56
}
// namespace std
57
58
#
endif
// INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_SWAP_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
swap.hpp
Generated by
1.13.2