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
16#include "stdlib/include/stdlib_detail/forward.hpp"
17#include "stdlib/include/stdlib_detail/is_assignable.hpp"
18#include "stdlib/include/stdlib_detail/is_move_constructible.hpp"
19#include "stdlib/include/stdlib_detail/move.hpp"
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
33exchange(T& target, U&& source) noexcept(is_nothrow_move_constructible_v<T> && is_nothrow_assignable_v<T&, U&&>) -> T {
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_
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 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