Namespaces
Variants
Views
Actions

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

From cppreference.com
< cpp‎ | types
Revision as of 17:52, 19 April 2012 by P12bot (Talk | contribs)

Template:cpp/types/sidebar Template:ddcl list begin <tr class="t-dsc-header">

<td>
Defined in header <type_traits>
</td>

<td></td> <td></td> </tr> <tr class="t-dcl ">

<td >
template< class T >
struct is_destructible;
</td>

<td > (1) </td> <td > (since C++11) </td> </tr> <tr class="t-dcl ">

<td >
template< class T >
struct is_trivially_destructible;
</td>

<td > (2) </td> <td > (since C++11) </td> </tr> <tr class="t-dcl ">

<td >
template< class T >
struct is_nothrow_destructible;
</td>

<td > (3) </td> <td > (since C++11) </td> </tr> Template:ddcl list end

1) If an imaginary struct containing a member object of type T has a non-deleted destructor, provides the member constant value equal Template:cpp. For any other type, value is Template:cpp.

2) same as 1), but the destructor does not call any operation that is not trivial.

3) same as 1), but the destructor is noexcept.

Contents

Inherited from std::integral_constant

Member constants

value
[static]
true if T is destructible, false otherwise
(public static member constant)

Member functions

operator bool
converts the object to bool, returns value
(public member function)
operator()
(C++14)
returns value
(public member function)

Member types

Type Definition
value_type bool
type 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.

Example

#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 nothrow destructible? "
              << std::is_nothrow_destructible<Foo>::value << '\n'
              << "Bar is trivally destructible? "
              << std::is_trivially_destructible<Bar>::value << '\n';
}

Output:

std::string is destructible? true
Foo is nothrow destructible? true
Bar is trivally destructible? true

See also

checks if a type has a constructor for specific arguments
(class template) [edit]
checks if a type has a virtual destructor
(class template) [edit]