template< class T >
struct is_destructible;
template< class T >
struct is_trivially_destructible;
template< class T >
struct is_nothrow_destructible;
1) If T
is a reference type, provides the member constant value equal to true.
If T
is (possibly cv-qualified) void, a function type, or an array of unknown bound, value equals false.
If
T
is an object type, then, for the type
U
that is
std::remove_all_extents<T>::type, if the expression
std::declval<U&>().~U()is well-formed in unevaluated context,
valueequals
true. Otherwise,
valueequals
false.
3) Same as (1), but the destructor is noexcept.
If T
is not a complete type, (possibly cv-qualified) void, or an array of unknown bound, the behavior is undefined.
If an instantiation of a template above depends, directly or indirectly, on an incomplete type, and that instantiation could yield a different result if that type were hypothetically completed, the behavior is undefined.
If the program adds specializations for any of the templates described on this page, the behavior is undefined.
[edit] Helper variable templatestemplate< class T >
constexpr bool is_destructible_v = is_destructible<T>::value;
template< class T >
constexpr bool is_trivially_destructible_v = is_trivially_destructible<T>::value;
template< class T >
constexpr bool is_nothrow_destructible_v = is_nothrow_destructible<T>::value;
T
is destructible, false otherwise
Because the C++ program terminates if a destructor throws an exception during stack unwinding (which usually cannot be predicted), all practical destructors are non-throwing even if they are not declared noexcept. All destructors found in the C++ standard library are non-throwing.
Storage occupied by trivially destructible objects may be reused without calling the destructor.
[edit] Possible implementation [edit] Example#include <iostream> #include <string> #include <type_traits> struct Foo { std::string str; ~Foo() noexcept {}; }; struct Bar { ~Bar() = default; }; static_assert(std::is_destructible<std::string>::value == true); static_assert(std::is_trivially_destructible_v<Foo> == false); static_assert(std::is_nothrow_destructible<Foo>() == true); static_assert(std::is_trivially_destructible<Bar>{} == true); int main() {}[edit] Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR Applied to Behavior as published Correct behavior LWG 2049 C++11 the specification was incompletable because of the imaginary wrapping struct made complete [edit] See alsoRetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4