Namespaces
Variants

std:: is_copy_constructible, std:: is_trivially_copy_constructible, std:: is_nothrow_copy_constructible

From ko.cppreference.net
Metaprogramming library
Type traits
Type categories
(C++11)
(C++11) ( DR* )
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
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
헤더에 정의됨 <type_traits>
template < class T >
struct is_copy_constructible ;
(1) (C++11부터)
template < class T >
struct is_trivially_copy_constructible ;
(2) (C++11부터)
template < class T >
struct is_nothrow_copy_constructible ;
(3) (C++11부터)
타입 특성 멤버 상수 value 의 값
T 가 참조 가능 타입 인 경우 T 가 참조 가능 타입이 아닌 경우
(1) std:: is_constructible < T, const T & > :: value false
(2) std:: is_trivially_constructible < T, const T & > :: value
(3) std:: is_nothrow_constructible < T, const T & > :: value

만약 T 가 완전한 타입이 아니거나, (cv 한정자가 있을 수 있음) void , 또는 알려지지 않은 경계의 배열인 경우, 동작은 정의되지 않습니다.

템플릿의 인스턴스화가 직접적 또는 간접적으로 불완전한 타입에 의존하고, 해당 타입이 가상적으로 완성되었을 때 인스턴스화 결과가 달라질 수 있는 경우, 그 동작은 정의되지 않습니다.

프로그램이 이 페이지에 설명된 템플릿들 중 어느 하나에 대해 특수화를 추가하는 경우, 그 동작은 정의되지 않습니다.

목차

헬퍼 변수 템플릿

template < class T >

inline constexpr bool is_copy_constructible_v =

is_copy_constructible < T > :: value ;
(C++17부터)
template < class T >

inline constexpr bool is_trivially_copy_constructible_v =

is_trivially_copy_constructible < T > :: value ;
(C++17부터)
template < class T >

inline constexpr bool is_nothrow_copy_constructible_v =

is_nothrow_copy_constructible < 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 >

가능한 구현

template<class T>
struct is_copy_constructible :
    std::is_constructible<T, typename std::add_lvalue_reference<
        typename std::add_const<T>::type>::type> {};
template<class T>
struct is_trivially_copy_constructible :
    std::is_trivially_constructible<T, typename std::add_lvalue_reference<
        typename std::add_const<T>::type>::type> {};
template<class T>
struct is_nothrow_copy_constructible :
    std::is_nothrow_constructible<T, typename std::add_lvalue_reference<
        typename std::add_const<T>::type>::type> {};

참고 사항

많은 구현에서, is_nothrow_copy_constructible 는 소멸자가 예외를 던지는지 여부도 확인합니다. 이는 실제로 noexcept ( T ( arg ) ) 와 동일하기 때문입니다. 동일한 사항이 is_trivially_copy_constructible 에도 적용되며, 이러한 구현에서는 소멸자가 trivial해야 합니다: GCC 버그 51452 , LWG 이슈 2116 .

예제

#include <string>
#include <type_traits>
struct S1
{
    std::string str; // 멤버가 비트리비얼 복사 생성자를 가짐
};
static_assert(std::is_copy_constructible_v<S1>);
static_assert(!std::is_trivially_copy_constructible_v<S1>);
struct S2
{
    int n;
    S2(const S2&) = default; // 트리비얼하고 논스로우
};
static_assert(std::is_trivially_copy_constructible_v<S2>);
static_assert(std::is_nothrow_copy_constructible_v<S2>);
struct S3
{
    S3(const S3&) = delete; // 명시적으로 삭제됨
};
static_assert(!std::is_copy_constructible_v<S3>);
struct S4
{
    S4(S4&) {}; // const를 바인딩할 수 없으므로 복사 생성 불가
};
static_assert(!std::is_copy_constructible_v<S4>);
int main() {}

결함 보고서

다음의 동작 변경 결함 보고서들은 이전에 발표된 C++ 표준에 소급 적용되었습니다.

DR 적용 대상 게시된 동작 올바른 동작
LWG 2196 C++11 const T & 를 형성할 수 없는 경우 동작이 불명확했음 이 경우 생성되는 값은 false 임

참고 항목

특정 인수들에 대한 생성자가 있는지 검사합니다
(클래스 템플릿)
기본 생성자가 있는지 검사합니다
(클래스 템플릿)
우측값 참조로부터 생성 가능한지 검사합니다
(클래스 템플릿)
해당 타입의 객체가 복사 생성과 이동 생성이 가능함을 명시합니다
(컨셉)