tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
is_swappable_with.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2// SPDX-FileCopyrightText: Copyright (C) 2019 Tobias Hienzsch
3
4#ifndef TETL_TYPE_TRAITS_IS_SWAPPABLE_WITH_HPP
5#define TETL_TYPE_TRAITS_IS_SWAPPABLE_WITH_HPP
6
7#include <etl/_cstddef/size_t.hpp>
8#include <etl/_type_traits/add_lvalue_reference.hpp>
9#include <etl/_type_traits/bool_constant.hpp>
10#include <etl/_type_traits/conjunction.hpp>
11#include <etl/_type_traits/declval.hpp>
12#include <etl/_type_traits/is_move_assignable.hpp>
13#include <etl/_type_traits/is_move_constructible.hpp>
14#include <etl/_type_traits/is_nothrow_move_assignable.hpp>
15#include <etl/_type_traits/is_nothrow_move_constructible.hpp>
16#include <etl/_type_traits/void_t.hpp>
17
18namespace etl {
19
20template <typename T>
21struct is_swappable;
22
23template <typename T>
25
26template <typename T>
27 requires(etl::is_move_constructible_v<T> && etl::is_move_assignable_v<T>)
28constexpr auto
30
31template <typename T, etl::size_t N>
32 requires(etl::is_swappable<T>::value)
33constexpr auto swap(T (&a)[N], T (&b)[N]) noexcept(etl::is_nothrow_swappable<T>::value) -> void;
34
35// swap(declval<T>(), declval<U>()) is not valid
36template <typename T, typename U, typename = void>
37struct _swappable_with_helper : false_type { }; // NOLINT
38
39// swap(declval<T>(), declval<U>()) is valid
40template <typename T, typename U>
41struct _swappable_with_helper<T, U, void_t<decltype(swap(declval<T>(), declval<U>()))>> : true_type { }; // NOLINT
42
43// Determine if expressions with type and value category T and U can be
44// swapped (and vice versa)
45template <typename T, typename U>
46struct is_swappable_with : bool_constant<conjunction_v<_swappable_with_helper<T, U>, _swappable_with_helper<U, T>>> { };
47
48template <typename T, typename U>
49inline constexpr bool is_swappable_with_v = is_swappable_with<T, U>::value;
50
51} // namespace etl
52
53#endif // TETL_TYPE_TRAITS_IS_SWAPPABLE_WITH_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 bool is_swappable_with_v
Definition is_swappable_with.hpp:49
constexpr auto swap(T(&a)[N], T(&b)[N]) noexcept(etl::is_nothrow_swappable< T >::value) -> void
Definition swap.hpp:35
Definition is_swappable_with.hpp:37
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:17
Definition is_swappable_with.hpp:46
If T is not a referenceable type (i.e., possibly cv-qualified void or a function type with a cv-quali...
Definition is_swappable.hpp:17