tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
is_destructible.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2// SPDX-FileCopyrightText: Copyright (C) 2021 Tobias Hienzsch
3
4#ifndef TETL_TYPE_TRAITS_IS_DESTRUCTIBLE_HPP
5#define TETL_TYPE_TRAITS_IS_DESTRUCTIBLE_HPP
6
7#include <etl/_type_traits/bool_constant.hpp>
8#include <etl/_type_traits/declval.hpp>
9#include <etl/_type_traits/disjunction.hpp>
10#include <etl/_type_traits/extent.hpp>
11#include <etl/_type_traits/is_function.hpp>
12#include <etl/_type_traits/is_reference.hpp>
13#include <etl/_type_traits/is_scalar.hpp>
14#include <etl/_type_traits/is_unbounded_array.hpp>
15#include <etl/_type_traits/is_void.hpp>
16#include <etl/_type_traits/remove_all_extents.hpp>
17#include <etl/_type_traits/type_identity.hpp>
18
19namespace etl {
20
21namespace detail {
22
23struct try_is_destructible_impl {
24 template <typename T, typename = decltype(etl::declval<T&>().~T())>
25 static auto test(int) -> etl::true_type;
26
27 template <typename>
28 static auto test(...) -> etl::false_type;
29};
30
31template <typename T>
32struct is_destructible_impl : try_is_destructible_impl {
33 using type = decltype(test<T>(0));
34};
35
36template <
37 typename T,
38 bool = etl::disjunction<etl::is_void<T>, etl::is_function<T>, etl::is_unbounded_array<T>>::value,
39 bool = etl::disjunction<etl::is_reference<T>, etl::is_scalar<T>>::value
40>
41struct is_destructible_safe;
42
43template <typename T>
44struct is_destructible_safe<T, false, false> : is_destructible_impl<typename etl::remove_all_extents_t<T>>::type { };
45
46template <typename T>
47struct is_destructible_safe<T, true, false> : etl::false_type { };
48
49template <typename T>
50struct is_destructible_safe<T, false, true> : etl::true_type { };
51
52} // namespace detail
53
54/// \brief Because the C++ program terminates if a destructor throws an
55/// exception during stack unwinding (which usually cannot be predicted), all
56/// practical destructors are non-throwing even if they are not declared
57/// noexcept. All destructors found in the C++ standard library are
58/// non-throwing.
59///
60/// https://en.cppreference.com/w/cpp/types/is_destructible
61template <typename T>
62struct is_destructible : detail::is_destructible_safe<T> { };
63
64template <typename Type>
65struct is_destructible<Type[]> : false_type { };
66
67template <>
68struct is_destructible<void> : false_type { };
69
70template <typename T>
71inline constexpr auto is_destructible_v = is_destructible<T>::value;
72
73} // namespace etl
74
75#endif // TETL_TYPE_TRAITS_IS_DESTRUCTIBLE_HPP
Definition adjacent_find.hpp:9
constexpr auto is_destructible_v
Definition is_destructible.hpp:71
Forms the logical disjunction of the type traits B..., effectively performing a logical OR on the seq...
Definition disjunction.hpp:15
Because the C++ program terminates if a destructor throws an exception during stack unwinding (which ...
Definition is_destructible.hpp:62
Checks whether T is an array type of unknown bound. Provides the member constant value which is equal...
Definition is_unbounded_array.hpp:15