Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/named req/Destructible"

From cppreference.com
< cpp‎ | named req
m (Text replace - "cpp/concept" to "cpp/named req")
m (fmt, .)
 
(4 intermediate revisions by 3 users not shown)
Line 5: Line 5:
  
 
===Requirements===
 
===Requirements===
 
+
The type {{tt|T}} satisfies {{named req/core|Destructible}} if
The type {{tt|T}} satisfies {{tt|Destructible}} if
+
  
 
Given
 
Given
* {{tt|u}}, a expression of type {{tt|T}}
+
* {{tt|u}}, an expression of type {{tt|T}}.
  
The following expressions must be valid and have their specified effects
+
The following expressions must be valid and have their specified effects.
  
 
{|table class=wikitable
 
{|table class=wikitable
Line 17: Line 16:
 
!Expression||Post-conditions
 
!Expression||Post-conditions
 
|-
 
|-
| {{c|u.~T()}}
+
|{{c|u.~T()}}
| All resources owned by {{tt|u}} are reclaimed, no exceptions are thrown.
+
|All resources owned by {{tt|u}} are reclaimed, no exceptions are thrown.
 
|}
 
|}
  
Line 24: Line 23:
 
Destructors are called implicitly at the end of [[cpp/language/lifetime|object lifetime]] such as when leaving [[cpp/language/scope|scope]] or by the [[cpp/language/delete|delete-expression]]. Explicit destructor call as shown in the type requirement table is rare.
 
Destructors are called implicitly at the end of [[cpp/language/lifetime|object lifetime]] such as when leaving [[cpp/language/scope|scope]] or by the [[cpp/language/delete|delete-expression]]. Explicit destructor call as shown in the type requirement table is rare.
  
Thanks to [[cpp/language/operator_member_access#Built-in_member_access_operators|pseudo destructor call]], all scalar types meet the requirement of {{ttb|Destructible}}, while array types and reference types do not. Note that {{lc|std::is_destructible}} allows arrays and reference types.
+
Thanks to [[cpp/language/operator_member_access#Built-in_member_access_operators|pseudo destructor call]], all scalar types meet the requirement of {{named req/core|Destructible}}, while array types and reference types do not. Note that {{lc|std::is_destructible}} allows arrays and reference types.
  
 
===See also===
 
===See also===
 
{{dsc begin}}
 
{{dsc begin}}
{{dsc inc | cpp/types/dsc is_destructible}}
+
{{dsc inc|cpp/types/dsc is_destructible}}
 +
{{dsc inc|cpp/concepts/dsc destructible}}
 
{{dsc end}}
 
{{dsc end}}
  
[[de:cpp/named req/Destructible]]
+
{{langlinks|de|es|fr|it|ja|pt|ru|zh}}
[[es:cpp/named req/Destructible]]
+
[[fr:cpp/named req/Destructible]]
+
[[it:cpp/named req/Destructible]]
+
[[ja:cpp/named req/Destructible]]
+
[[pt:cpp/named req/Destructible]]
+
[[ru:cpp/named req/Destructible]]
+
[[zh:cpp/named req/Destructible]]
+

Latest revision as of 10:43, 8 August 2023

 
 
C++ named requirements
 

Specifies that an instance of the type can be destructed.

[edit] Requirements

The type T satisfies Destructible if

Given

  • u, an expression of type T.

The following expressions must be valid and have their specified effects.

Expression Post-conditions
u.~T() All resources owned by u are reclaimed, no exceptions are thrown.

[edit] Notes

Destructors are called implicitly at the end of object lifetime such as when leaving scope or by the delete-expression. Explicit destructor call as shown in the type requirement table is rare.

Thanks to pseudo destructor call, all scalar types meet the requirement of Destructible, while array types and reference types do not. Note that std::is_destructible allows arrays and reference types.

[edit] See also

checks if a type has a non-deleted destructor
(class template) [edit]
specifies that an object of the type can be destroyed
(concept) [edit]