Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
is_destructible.hpp
Go to the documentation of this file.
1// Copyright 2024, Toyota Motor Corporation
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
5#ifndef INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_IS_DESTRUCTIBLE_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_IS_DESTRUCTIBLE_HPP_
7
8// parasoft-begin-suppress CERT_CPP-DCL58-a-2 "Part of a standard library implementation"
9// parasoft-begin-suppress AUTOSAR-A17_6_1-a-2 "Part of a standard library implementation"
10
11// IWYU pragma: private, include <type_traits>
12// IWYU pragma: friend "stdlib_detail/.*"
13
14#include "stdlib/include/stdlib_detail/cstdint.hpp"
15#include "stdlib/include/stdlib_detail/declval.hpp"
16#include "stdlib/include/stdlib_detail/enable_if.hpp"
17#include "stdlib/include/stdlib_detail/integral_constant.hpp"
18#include "stdlib/include/stdlib_detail/is_reference.hpp"
19#include "stdlib/include/stdlib_detail/remove_all_extents.hpp"
20#include "stdlib/include/stdlib_detail/remove_reference.hpp"
21// parasoft-begin-suppress AUTOSAR-A16_2_2-a "False positive: This header's definitions are used"
22#include "stdlib/include/stdlib_detail/void_t.hpp"
23// parasoft-end-suppress AUTOSAR-A16_2_2-a
24
25// parasoft-begin-suppress AUTOSAR-A16_0_1-a-2 "Conditional defines permitted by A16-0-1 Permit #2"
26// parasoft-begin-suppress AUTOSAR-A16_0_1-d-2 "Conditional defines permitted by A16-0-1 Permit #2"
27#ifdef __clang__
28#define ARENE_STDLIB_TRIVIALLY_DESTRUCTIBLE_CHECK __is_trivially_destructible
29#else
30#define ARENE_STDLIB_TRIVIALLY_DESTRUCTIBLE_CHECK __has_trivial_destructor
31#endif
32// parasoft-end-suppress AUTOSAR-A16_0_1-d-2
33// parasoft-end-suppress AUTOSAR-A16_0_1-a-2
34
35namespace std {
37
38// parasoft-begin-suppress AUTOSAR-A2_7_3-a "False positive: all declarations
39// and typedefs *are* preceded by a comment with @brief"
40
41/// @brief Type trait to detect if a type is an array of unknown bound
42/// @tparam Type The type to check
43template <typename Type>
44extern constexpr bool is_array_of_unknown_bound_v = false;
45
46/// @brief Type trait to detect if a type is an array of unknown bound
47/// @tparam Type The type to check
48template <typename Type>
49// NOLINTNEXTLINE(hicpp-avoid-c-arrays)
50extern constexpr bool is_array_of_unknown_bound_v<Type[]> = true;
51
52/// @brief The result of the "destructible" check: is the type not destructible, destructible but throwing, or
53/// nothrow-destructible?
55
56/// @brief Type trait to check whether a type is destructible, and if so, if it is no-throw destructible
57/// @tparam Type The type to check
58template <typename Type, typename = void>
60
61/// @brief Type trait to check whether a type is destructible, and if so, if it is no-throw destructible
62/// @tparam Type The type to check
63template <typename Type>
66
67/// @brief Type trait to check whether a type is destructible, and if so, if it is no-throw destructible
68/// @tparam Type The type to check
69template <typename Type>
72
73/// @brief Helper alias for the non-array non-reference "raw" type for a given type
74/// @tparam Type the type to get the raw type for
75template <typename Type>
77
78// parasoft-begin-suppress AUTOSAR-A2_7_3-b "False positive: these is a comment with @return"
79// parasoft-begin-suppress AUTOSAR-M3_3_2-a-2 "False positive: Declaration must be non-static to avoid ODR violations"
80/// @brief Helper function for checking if a type is destructible
81/// @tparam T The type to check
82/// @return Nothing
83template <class T>
84constexpr auto try_destroy() noexcept(noexcept(declval<T&>().~T())) -> decltype(declval<T&>().~T());
85// parasoft-end-suppress AUTOSAR-A2_7_3-b
86// parasoft-end-suppress AUTOSAR-M3_3_2-a-2
87
88/// @brief Type trait to check whether a type is destructible, and if so, if it is no-throw destructible
89/// @tparam Type The type to check
90template <typename Type>
91extern constexpr auto destructible_result_v<
92 Type,
95 void_t<decltype(try_destroy<raw_type_t<Type>>())>>> =
98
99// parasoft-end-suppress AUTOSAR-A2_7_3-a
100
101} // namespace is_destructible_detail
102
103/// @brief Type trait to detect if a type is destructible
104/// @tparam Type The type to (try to) destruct
105template <typename Type>
108
109/// @brief Type trait to detect if a type is destructible
110/// @tparam Type The type to (try to) destruct
111template <typename Type>
113
114/// @brief Type trait to detect if a type is destructible without throwing an exception
115/// @tparam Type The type to (try to) destruct
116template <typename Type>
119
120/// @brief Type trait to detect if a type is destructible without throwing an exception
121/// @tparam Type The type to (try to) destruct
122template <typename Type>
124
125/// @brief Type trait to detect if a type is trivially destructible
126/// @tparam Type The type to (try to) destruct
127template <typename Type>
128extern constexpr bool is_trivially_destructible_v =
130
131/// @brief Type trait to detect if a type is trivially destructible
132/// @tparam Type The type to (try to) destruct
133template <typename Type>
135
136} // namespace std
137
138#endif // INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_IS_DESTRUCTIBLE_HPP_
Type trait to detect if a type is destructible.
Definition is_destructible.hpp:112
Type trait to detect if a type is destructible without throwing an exception.
Definition is_destructible.hpp:123
Type trait to detect if a type is trivially destructible.
Definition is_destructible.hpp:134
#define ARENE_STDLIB_TRIVIALLY_DESTRUCTIBLE_CHECK
Definition is_destructible.hpp:30
Definition is_destructible.hpp:36
is_destructible_result
The result of the "destructible" check: is the type not destructible, destructible but throwing,...
Definition is_destructible.hpp:54
@ destructible
Definition is_destructible.hpp:54
@ nothrow_destructible
Definition is_destructible.hpp:54
@ not_destructible
Definition is_destructible.hpp:54
constexpr bool is_array_of_unknown_bound_v
Type trait to detect if a type is an array of unknown bound.
constexpr auto try_destroy() noexcept(noexcept(declval< T & >().~T())) ->
Helper function for checking if a type is destructible.
constexpr bool is_array_of_unknown_bound_v< Type[]>
Type trait to detect if a type is an array of unknown bound.
constexpr auto destructible_result_v
Type trait to check whether a type is destructible, and if so, if it is no-throw destructible.
constexpr bool is_trivially_destructible_v
Type trait to detect if a type is trivially destructible.
constexpr bool is_destructible_v
Type trait to detect if a type is destructible.
constexpr bool is_nothrow_destructible_v
Type trait to detect if a type is destructible without throwing an exception.
constexpr auto operator()(::arene::base::result< void, E > const &value) const noexcept(noexcept(hash< E >{}(std::declval< E const & >()))) -> std::size_t
Calculate the hash of a result.
Definition result.hpp:1827