std:: is_default_constructible, std:: is_trivially_default_constructible, std:: is_nothrow_default_constructible
|
헤더 파일에 정의됨
<type_traits>
|
||
|
template
<
class
T
>
struct is_default_constructible ; |
(1) | (C++11부터) |
|
template
<
class
T
>
struct is_trivially_default_constructible ; |
(2) | (C++11부터) |
|
template
<
class
T
>
struct is_nothrow_default_constructible ; |
(3) | (C++11부터) |
만약
T
가 완전한 타입이 아니거나, (cv 한정자가 있을 수 있음)
void
, 또는 알려지지 않은 경계의 배열인 경우, 동작은 정의되지 않습니다.
템플릿의 인스턴스화가 직접적 또는 간접적으로 불완전한 타입에 의존하고, 해당 타입이 가상적으로 완성되었을 때 인스턴스화 결과가 달라질 수 있는 경우, 그 동작은 정의되지 않습니다.
프로그램이 이 페이지에 설명된 템플릿들 중 어느 하나에 대해 특수화를 추가하는 경우, 동작은 정의되지 않습니다.
목차 |
헬퍼 변수 템플릿
|
template
<
class
T
>
inline
constexpr
bool
is_default_constructible_v
=
|
(C++17부터) | |
|
template
<
class
T
>
inline
constexpr
bool
is_trivially_default_constructible_v
=
|
(C++17부터) | |
|
template
<
class
T
>
inline
constexpr
bool
is_nothrow_default_constructible_v
=
|
(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 > |
가능한 구현
template<class T> struct is_default_constructible : std::is_constructible<T> {}; template<class T> struct is_trivially_default_constructible : std::is_trivially_constructible<T> {}; template<class T> struct is_nothrow_default_constructible : std::is_nothrow_constructible<T> {}; |
참고 사항
많은 구현에서,
std::is_nothrow_default_constructible
는 소멸자가 예외를 던지는지 여부도 확인합니다. 이는 사실상
noexcept
(
T
(
)
)
와 동일하기 때문입니다. 동일한 사항이
std::is_trivially_default_constructible
에도 적용되며, 이러한 구현에서는 소멸자가 trivial해야 합니다:
GCC 버그 51452
,
LWG 이슈 2116
.
std
::
is_default_constructible
<
T
>
는
T x;
가 컴파일되는지 테스트하지 않습니다; 대신 빈 인수 목록으로
직접 초기화(direct-initialization)
를 시도합니다 (
std::is_constructible
참조). 따라서
std
::
is_default_constructible_v
<
const
int
>
와
std
::
is_default_constructible_v
<
const
int
[
10
]
>
는
true
입니다.
예제
#include <string> #include <type_traits> struct S1 { std::string str; // 멤버가 trivial하지 않은 기본 생성자를 가짐 }; static_assert(std::is_default_constructible_v<S1> == true); static_assert(std::is_trivially_default_constructible_v<S1> == false); struct S2 { int n; S2() = default; // trivial하고 non-throwing }; static_assert(std::is_trivially_default_constructible_v<S2> == true); static_assert(std::is_nothrow_default_constructible_v<S2> == true); int main() {}
참고 항목
|
(C++11)
(C++11)
(C++11)
|
특정 인수에 대한 생성자가 있는지 확인
(클래스 템플릿) |
|
(C++11)
(C++11)
(C++11)
|
복사 생성자가 있는지 확인
(클래스 템플릿) |
|
(C++11)
(C++11)
(C++11)
|
우측값 참조로부터 생성 가능한지 확인
(클래스 템플릿) |
|
(C++20)
|
타입의 객체가 기본 생성될 수 있음을 명시
(컨셉트) |