Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

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

      From cppreference.com
      <cpp‎ |types
       
       
      Metaprogramming library
      Type traits
      Type categories
      (C++11)
      (C++11)(DR*)
      (C++11)
      (C++11)
      (C++11)
      (C++11)
      (C++11)
      (C++11) 
      Type properties
      (C++11)
      (C++11)
      (C++14)
      (C++11)(deprecated in C++26)
      (C++11)(until C++20*)
      (C++11)(deprecated in C++20)
      (C++11)
      Type trait constants
      Metafunctions
      (C++17)
      Supported operations
      is_destructibleis_trivially_destructibleis_nothrow_destructible
      (C++11)(C++11)(C++11)

      Relationships and property queries
      Type modifications
      Type transformations
      (C++11)(deprecated in C++23)
      (C++11)(deprecated in C++23)
      (C++11)
      (C++11)(until C++20*)(C++17)

      Compile-time rational arithmetic
      Compile-time integer sequences
       
      Defined in header<type_traits>
      template<class T>
      struct is_destructible;
      (1)(since C++11)
      template<class T>
      struct is_trivially_destructible;
      (2)(since C++11)
      template<class T>
      struct is_nothrow_destructible;
      (3)(since C++11)
      1) IfT is a reference type, provides the member constantvalue equal totrue.
      IfT is (possibly cv-qualified)void, a function type, or an array of unknown bound,value equalsfalse.
      IfT is an object type, then, for the typeU that isstd::remove_all_extents<T>::type, if the expressionstd::declval<U&>().~U() is well-formed in unevaluated context,value equalstrue. Otherwise,value equalsfalse.
      2) Same as(1) and additionallystd::remove_all_extents<T>::type is either a non-class type or a class type with atrivial destructor.
      3) Same as(1), but the destructor isnoexcept.

      IfT 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.

      Contents

      [edit]Helper variable templates

      template<class T>
      constexprbool is_destructible_v= is_destructible<T>::value;
      (since C++17)
      template<class T>
      constexprbool is_trivially_destructible_v= is_trivially_destructible<T>::value;
      (since C++17)
      template<class T>
      constexprbool is_nothrow_destructible_v= is_nothrow_destructible<T>::value;
      (since C++17)
      [edit]

      Inherited fromstd::integral_constant

      Member constants

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

      Member functions

      operator bool
      converts the object tobool, returnsvalue
      (public member function)
      operator()
      (C++14)
      returnsvalue
      (public member function)

      Member types

      Type Definition
      value_typebool
      typestd::integral_constant<bool, value>

      [edit]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 bytrivially destructible objectsmay be reused without calling the destructor.

      [edit]Possible implementation

      is_destructible (1)
      // C++20 requiredtemplate<typename t>struct is_destructible:std::integral_constant<bool, requires(t object){ object.~t();}>{};
      is_trivially_destructible (2)
      // Not real C++. Shall P2996 be approved, the following implementation will be available:template<typename t>struct is_trivially_destructible:std::integral_constant<bool, std::meta::type_is_trivially_destructible(^t)>{};
      is_nothrow_destructible (3)
      // C++20 requiredtemplate<typename t>struct is_nothrow_destructible:std::integral_constant<bool, requires(t object){{object.~t()}noexcept;}>{};

      [edit]Example

      Run this code
      #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.

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

      [edit]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]
      specifies that an object of the type can be destroyed
      (concept)[edit]
      destructor releases claimed resources[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/types/is_destructible&oldid=176474"

      [8]ページ先頭

      ©2009-2025 Movatter.jp