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// SPDX-FileCopyrightText: Copyright (C) 2020 Tobias Hienzsch
3
4#ifndef TETL_UTILITY_SWAP_HPP
5#define TETL_UTILITY_SWAP_HPP
6
7#include <etl/_cstddef/size_t.hpp>
8#include <etl/_type_traits/is_move_assignable.hpp>
9#include <etl/_type_traits/is_move_constructible.hpp>
10#include <etl/_type_traits/is_nothrow_move_assignable.hpp>
11#include <etl/_type_traits/is_nothrow_move_constructible.hpp>
12#include <etl/_type_traits/is_swappable.hpp>
13#include <etl/_type_traits/remove_reference.hpp>
14#include <etl/_utility/move.hpp>
15
16namespace etl {
17
18/// \brief Exchanges the given values. Swaps the values a and b. This overload
19/// does not participate in overload resolution unless
20/// etl::is_move_constructible_v<T> && etl::is_move_assignable_v<T> is true.
21///
22/// \details https://en.cppreference.com/w/cpp/algorithm/swap
23template <typename T>
24 requires(etl::is_move_constructible_v<T> and etl::is_move_assignable_v<T>)
25constexpr auto
27{
28 T temp(etl::move(a));
29 a = etl::move(b);
30 b = etl::move(temp);
31}
32
33template <typename T, etl::size_t N>
34 requires(etl::is_swappable_v<T>)
35constexpr auto swap(T (&a)[N], T (&b)[N]) noexcept(etl::is_nothrow_swappable<T>::value) -> void
36{
37 for (etl::size_t i = 0; i < N; ++i) {
38 swap(a[i], b[i]);
39 }
40}
41
42} // namespace etl
43
44#endif // TETL_UTILITY_SWAP_HPP
Definition adjacent_find.hpp:9
constexpr auto swap(T &a, T &b) noexcept -> void
Exchanges the given values. Swaps the values a and b. This overload does not participate in overload ...
Definition swap.hpp:26
constexpr auto swap(T(&a)[N], T(&b)[N]) noexcept(etl::is_nothrow_swappable< T >::value) -> void
Definition swap.hpp:35