std::is_des...estructible(3)
π std::is_des...estructible(3) π
Okay bestie, this page is straight from the C++ Standard Libary (yes, that's how it's spelled on the page, we are not fixing it π
) and it's all about the destructible-checking trio. The NAME section is serving std::is_destructible,std::is_trivially_destructible,std::is_nothrow_destructible β that's the whole guest list, no cap.
πΈ Synopsis πΈ
Defined in header <type_traits>
template< class T > (1) (since C++11)
struct is_destructible;
template< class T > (2) (since C++11)
struct is_trivially_destructible;
template< class T > (3) (since C++11)
struct is_nothrow_destructible;
- If
Tis a reference type, it provides the member constantvalueequal totrue. IfTis a (possibly cv-qualified)void, a function type, or an array of unknown bound,valueequalsfalse. IfTis an object type, then, for the typeUthat isstd::remove_all_extents<T>::type, if the expressionstd::declval<U&>().~U()is well-formed in unevaluated context,valueequalstrue. Otherwise,valueequalsfalse. - Same as (1), and additionally
std::remove_all_extents<T>::typeis either a non-class type or a class type with a trivial destructor. - Same as (1), but the destructor is
noexcept.
β οΈ Undefined behavior alert, bestie: IfTis not a complete type, (possibly cv-qualified)void, or an array of unknown bound, the behavior is undefined.
β οΈ Also 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.
β οΈ And one more, fr fr: if the program adds specializations for any of the templates described on this page, the behavior is undefined.
π§Έ Member constants π§Έ
valueβtrueifTis destructible,falseotherwise. It's[static](public static member constant). β¨
π Member functions π
operator boolβ converts the object tobool, returnsvalue(public member function).operator()β returnsvalue(C++14)(public member function).
π¦ Member types π¦
value_typeβbooltypeβstd::integral_constant<bool, value>
π 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. Iconic behavior, honestly. - Storage occupied by trivially destructible objects may be reused without calling the destructor.
π§ͺ Example π§ͺ
// Run this code πββοΈπ¨
#include <iostream>
#include <string>
#include <type_traits>
struct Foo
{
std::string str;
~Foo() noexcept {};
};
struct Bar
{
~Bar() = default;
};
int main()
{
std::cout << std::boolalpha
<< "std::string is destructible? "
<< std::is_destructible<std::string>::value << '\n'
<< "Foo is trivially destructible? "
<< std::is_trivially_destructible_v<Foo> << '\n'
<< "Foo is nothrow destructible? "
<< std::is_nothrow_destructible<Foo>() << '\n'
<< "Bar is trivially destructible? "
<< std::is_trivially_destructible<Bar>{} << '\n';
}
π Output π
std::string is destructible? true
Foo is trivially destructible? false
Foo is nothrow destructible? true
Bar is trivially destructible? true
π©Ή Defect reports π©Ή
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
- DR:
LWG 2049β Applied to:C++11β Behavior as published: the specification was incompletable because of the imaginary wrapping struct. Correct behavior: made complete.
π See also π
is_constructibleis_trivially_constructibleis_nothrow_constructibleβ checks if a type has a constructor for specific arguments; markers:(C++11),(class template),(C++11),(C++11).has_virtual_destructorβ checks if a type has a virtual destructor;(C++11),(class template).destructibleβ specifies that an object of the type can be destroyed;(C++20),(concept).destructorβ releases claimed resources.
Source: http://cppreference.com β¨ Version/date: 2024.06.10 β¨ Page: std::is_des...estructible(3) β bye bestie, go check those destructors π«Άπ
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms