std::is_destructible, std::is_trivially_destructible, std::is_nothrow_destructible

Header: <type_traits>

  1. If T is a reference type, provides the member constant value equal to true.

# Declarations

template< class T >
struct is_destructible;

(since C++11)

template< class T >
struct is_trivially_destructible;

(since C++11)

template< class T >
struct is_nothrow_destructible;

(since C++11)

# 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 <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() {}

# Defect reports

DRApplied toBehavior as publishedCorrect behavior
LWG 2049C++11the specification was incompletable because of the imaginary wrapping structmade complete

# See also