std::meta::is_destructible_type, std::meta::is_trivially_destructible_type, std::meta::is_nothrow_destructible_type
| Defined in header <meta>
|
||
consteval bool is_destructible_type( std::meta::info r );
|
(1) | (since C++26) |
consteval bool is_trivially_destructible_type( std::meta::info r );
|
(2) | (since C++26) |
consteval bool is_nothrow_destructible_type( std::meta::info r );
|
(3) | (since C++26) |
Returns true if r represents a type T that is
destructible,
trivially destructible or
non-throwing destructible, respectively, that is, T has an appropriate destructor.
return std::is_destructible_v<T>;.return std::is_trivially_destructible_v<T>;.return std::is_nothrow_destructible_v<T>;.If T is not a complete type, (possibly cv-qualified) void, or an array of unknown bound, the program is ill-formed.
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 program is ill-formed.
Parameters
| r | - | a reflection value to test |
Return value
true if r represents a type that is:
as described above. Otherwise, false.
Exceptions
Throws std::meta::exception if r does not represent a type or type alias.
Notes
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.
Example
#include <meta>
#include <string>
struct Foo
{
std::string str;
~Foo() noexcept {};
};
struct Bar
{
~Bar() = default;
};
static_assert(
is_destructible_type(^^std::string) == true and
is_destructible_type(^^Foo) == true and
is_trivially_destructible_type(^^Foo) == false and
is_nothrow_destructible_type(^^Foo) == true and
is_trivially_destructible_type(^^Bar) == true and
"");
int main() {}
See also
(C++26)(C++26)(C++26) |
checks if reflected type has a constructor for specific arguments (function template) |
(C++26) |
checks if reflected type has a virtual destructor (function) |
(C++20) |
specifies that an object of the type can be destroyed (concept) |
| destructor | releases claimed resources |
(C++11)(C++11)(C++11) |
checks if a type has a non-deleted destructor (class template) |