tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
swap.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2
3#ifndef TETL_UTILITY_SWAP_HPP
4#define TETL_UTILITY_SWAP_HPP
5
13#include <etl/_utility/move.hpp>
14
15namespace etl {
16
22template <typename T>
24constexpr auto swap(T& a, T& b)
26{
27 T temp(etl::move(a));
28 a = etl::move(b);
29 b = etl::move(temp);
30}
31
32template <typename T, etl::size_t N>
34constexpr auto swap(T (&a)[N], T (&b)[N]) noexcept(etl::is_nothrow_swappable<T>::value) -> void
35{
36 for (etl::size_t i = 0; i < N; ++i) {
37 swap(a[i], b[i]);
38 }
39}
40
41} // namespace etl
42
43#endif // TETL_UTILITY_SWAP_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 bool is_move_constructible_v
Definition is_move_constructible.hpp:20
constexpr bool is_swappable_v
Definition is_swappable.hpp:21
auto swap(inplace_function< R(Args...), Capacity, Alignment > &lhs, inplace_function< R(Args...), Capacity, Alignment > &rhs) noexcept -> void
Overloads the etl::swap algorithm for etl::inplace_function. Exchanges the state of lhs with that of ...
Definition inplace_function.hpp:249
constexpr bool is_nothrow_move_assignable_v
Definition is_nothrow_move_assignable.hpp:28
TETL_BUILTIN_SIZET size_t
etl::size_t is the unsigned integer type of the result of the sizeof operator.
Definition size_t.hpp:14
constexpr bool is_move_assignable_v
Definition is_move_assignable.hpp:29
If T is not a referenceable type (i.e., possibly cv-qualified void or a function type with a cv-quali...
Definition is_nothrow_swappable.hpp:16