tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
exchange.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2
3#ifndef TETL_UTILITY_EXCHANGE_HPP
4#define TETL_UTILITY_EXCHANGE_HPP
5
10
11namespace etl {
12
15template <typename T, typename U = T>
16[[nodiscard]] constexpr auto exchange(T& obj, U&& newValue)
18{
19 T oldValue = etl::move(obj);
20 obj = etl::forward<U>(newValue);
21 return oldValue;
22}
23
24} // namespace etl
25
26#endif // TETL_UTILITY_EXCHANGE_HPP
constexpr auto move(InputIt first, InputIt last, OutputIt destination) -> OutputIt
Moves the elements in the range [first, last), to another range beginning at destination,...
Definition move.hpp:26
Definition adjacent_find.hpp:8
constexpr bool is_nothrow_move_constructible_v
Definition is_nothrow_move_constructible.hpp:20
constexpr auto exchange(T &obj, U &&newValue) noexcept(etl::is_nothrow_move_constructible_v< T > and etl::is_nothrow_assignable_v< T &, U >) -> T
Replaces the value of obj with new_value and returns the old value of obj.
Definition exchange.hpp:16
constexpr bool is_nothrow_assignable_v
Definition is_nothrow_assignable.hpp:24
constexpr auto forward(remove_reference_t< T > &param) noexcept -> T &&
Forwards lvalues as either lvalues or as rvalues, depending on T. When t is a forwarding reference (a...
Definition forward.hpp:18