Difference between revisions of "cpp/named req/Destructible"
From cppreference.com
m (Text replace - "cpp/concept" to "cpp/named req") |
Andreas Krug (Talk | contribs) 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 {{ | + | |
Given | Given | ||
− | * {{tt|u}}, | + | * {{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 {{ | + | 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}} | ||
− | + | {{langlinks|de|es|fr|it|ja|pt|ru|zh}} | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + |
Latest revision as of 10:43, 8 August 2023
Specifies that an instance of the type can be destructed.
[edit] Requirements
The type T
satisfies Destructible if
Given
-
u
, an expression of typeT
.
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
(C++11)(C++11)(C++11) |
checks if a type has a non-deleted destructor (class template) |
(C++20) |
specifies that an object of the type can be destroyed (concept) |