Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
exchange.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_EXCHANGE_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_EXCHANGE_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// parasoft-begin-suppress AUTOSAR-A7_1_5-a-2 "Trailing return syntax permitted by A7-1-5 Permit #1 v1.0.0"
15
20
21namespace std {
22// parasoft-begin-suppress AUTOSAR-M3_3_2-a-2 "False positive: inline function used in multiple translation units"
23/// @brief Assign a new value to an object and return the old value. Implements @c std::exchange
24/// @tparam T The type of the object to update
25/// @tparam U The type of the source
26/// @param target The object to update
27/// @param source The source
28/// @return The old value
29/// @pre @c T must be move-constructible
30/// @pre @c is_assignable_v<T&,U&&> must be true
31template <typename T, typename U = T>
32constexpr auto
34 T old{std::move(target)};
35 target = std::forward<U>(source);
36 return old;
37}
38// parasoft-end-suppress AUTOSAR-M3_3_2-a-2
39
40} // namespace std
41
42#endif // INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_EXCHANGE_HPP_
STL namespace.
constexpr auto move(T &&value) noexcept -> remove_reference_t< T > &&
Cast a value to an rvalue.
Definition move.hpp:30
constexpr bool is_nothrow_assignable_v
Type trait to detect if an instance of To is assignable to from arguments of From without throwing.
constexpr bool is_nothrow_move_constructible_v
Type trait to detect if an instance of T is move constructible without throwing.
constexpr auto exchange(T &target, U &&source) noexcept(is_nothrow_move_constructible_v< T > &&is_nothrow_assignable_v< T &, U && >) -> T
Assign a new value to an object and return the old value. Implements std::exchange.
Definition exchange.hpp:33
constexpr auto forward(remove_reference_t< T > &value) noexcept -> T &&
Cast a value to an rvalue if T is an rvalue or rvalue reference, otherwise forward an lvalue referenc...
Definition forward.hpp:24