std:: is_destructible, std:: is_trivially_destructible, std:: is_nothrow_destructible
From cppreference.net
|
헤더 파일에 정의됨
<type_traits>
|
||
|
template
<
class
T
>
struct is_destructible ; |
(1) | (C++11부터) |
|
template
<
class
T
>
struct is_trivially_destructible ; |
(2) | (C++11부터) |
|
template
<
class
T
>
struct is_nothrow_destructible ; |
(3) | (C++11부터) |
1)
만약
T
가 참조 타입인 경우, 멤버 상수
value
를
true
로 제공합니다.
만약
T
가 (가능하게 cv 한정된)
void
, 함수 타입, 또는 알려지지 않은 경계의 배열인 경우,
value
는
false
와 같습니다.
만약
T
가 객체 타입이라면,
U
가
std::
remove_all_extents
<
T
>
::
type
인 타입일 때, 표현식
std::
declval
<
U
&
>
(
)
.~U
(
)
가 평가되지 않은 문맥에서 유효하다면,
value
는
true
와 같습니다. 그렇지 않다면,
value
는
false
와 같습니다.
2)
(1)
와 동일하고 추가적으로
std::
remove_all_extents
<
T
>
::
type
는 비클래스 타입이거나
trivial destructor
를 가진 클래스 타입입니다.
3)
(1)
과 동일하지만, 소멸자가
noexcept
입니다.
만약
T
가 완전한 타입이 아니거나, (cv 한정자가 있을 수 있음)
void
, 또는 알려지지 않은 경계의 배열인 경우, 동작은 정의되지 않습니다.
템플릿의 인스턴스화가 직접적 또는 간접적으로 불완전한 타입에 의존하고, 해당 타입이 가상적으로 완성되었을 때 인스턴스화 결과가 달라질 수 있는 경우, 그 동작은 정의되지 않습니다.
프로그램이 이 페이지에 설명된 템플릿들 중 어느 것에 대해 특수화를 추가하는 경우, 동작은 정의되지 않습니다.
목차 |
헬퍼 변수 템플릿
|
template
<
class
T
>
constexpr bool is_destructible_v = is_destructible < T > :: value ; |
(C++17부터) | |
|
template
<
class
T
>
constexpr bool is_trivially_destructible_v = is_trivially_destructible < T > :: value ; |
(C++17부터) | |
|
template
<
class
T
>
constexpr bool is_nothrow_destructible_v = is_nothrow_destructible < T > :: value ; |
(C++17부터) | |
std:: integral_constant 로부터 상속됨
멤버 상수
|
value
[static]
|
true
만약
T
가 파괴 가능한 경우,
false
그렇지 않은 경우
(public static member constant) |
멤버 함수
|
operator bool
|
객체를
bool
로 변환,
value
반환
(public member function) |
|
operator()
(C++14)
|
value
반환
(public member function) |
멤버 타입
| 타입 | 정의 |
value_type
|
bool |
type
|
std:: integral_constant < bool , value > |
참고 사항
C++ 프로그램은 스택 풀기 중에 소멸자가 예외를 던지면 종료되기 때문에(이는 일반적으로 예측할 수 없음), 모든 실용적인 소멸자는 noexcept로 선언되지 않았더라도 예외를 던지지 않습니다. C++ 표준 라이브러리에서 찾을 수 있는 모든 소멸자는 예외를 던지지 않습니다.
trivially destructible 객체들이 차지하는 저장 공간은 소멸자를 호출하지 않고 재사용 될 수 있습니다.
가능한 구현
| is_destructible (1) |
|---|
// C++20 required template<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 required template<typename t> struct is_nothrow_destructible : std::integral_constant<bool, requires(t object) { {object.~t()} noexcept; }> {}; |
예제
이 코드 실행
#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() {}
결함 보고서
다음의 동작 변경 결함 보고서들은 이전에 발표된 C++ 표준에 소급 적용되었습니다.
| DR | 적용 대상 | 게시된 동작 | 올바른 동작 |
|---|---|---|---|
| LWG 2049 | C++11 | 가상의 래핑 구조체로 인해 명세가 완성 불가능했음 | 완성됨 |
참고 항목
|
(C++11)
(C++11)
(C++11)
|
특정 인수들에 대한 생성자를 가지는지 검사합니다
(클래스 템플릿) |
|
(C++11)
|
가상 소멸자를 가지는지 검사합니다
(클래스 템플릿) |
|
(C++20)
|
해당 타입의 객체가 파괴될 수 있음을 명시합니다
(컨셉트) |
| destructor | 확보한 자원을 해제합니다 |