Namespaces
Variants

std:: is_copy_assignable, std:: is_trivially_copy_assignable, std:: is_nothrow_copy_assignable

From 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
is_copy_assignable is_trivially_copy_assignable is_nothrow_copy_assignable
(C++11) (C++11) (C++11)

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_assignable ;
(1) (C++11부터)
template < class T >
struct is_trivially_copy_assignable ;
(2) (C++11부터)
template < class T >
struct is_nothrow_copy_assignable ;
(3) (C++11부터)
타입 특성 멤버 상수 value 의 값
T 참조 가능 타입 인 경우 T 가 참조 가능 타입이 아닌 경우
(1) std:: is_assignable < T & , const T & > :: value false
(2) std:: is_trivially_assignable < T & , const T & > :: value
(3) std:: is_nothrow_assignable < T & , const T & > :: value

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

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

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

목차

헬퍼 변수 템플릿

template < class T >

inline constexpr bool is_copy_assignable_v =

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

inline constexpr bool is_trivially_copy_assignable_v =

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

inline constexpr bool is_nothrow_copy_assignable_v =

is_nothrow_copy_assignable < 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_assignable
    : std::is_assignable<typename std::add_lvalue_reference<T>::type,
                         typename std::add_lvalue_reference<const T>::type> {};
template<class T>
struct is_trivially_copy_assignable
    : std::is_trivially_assignable<typename std::add_lvalue_reference<T>::type,
                                   typename std::add_lvalue_reference<const T>::type> {};
template<class T>
struct is_nothrow_copy_assignable
    : std::is_nothrow_assignable<typename std::add_lvalue_reference<T>::type,
                                 typename std::add_lvalue_reference<const T>::type> {};
*모든 C++ 코드는 원본 그대로 유지되었으며, HTML 태그와 속성도 수정되지 않았습니다. 번역할 일반 텍스트가 포함되어 있지 않으므로 원본 내용이 그대로 유지됩니다.*

참고 사항

특성 std::is_copy_assignable CopyAssignable 보다 덜 엄격합니다. 왜냐하면 대입 연산의 결과 타입(이는 CopyAssignable 타입의 경우 반드시 T 타입의 lvalue이어야 함)을 확인하지 않고, 인자 표현식이 변경되지 않는다는 의미론적 요구사항도 확인하지 않기 때문입니다. 또한 모든 CopyAssignable 타입에 요구되는 MoveAssignable T 가 만족하는지 확인하지 않습니다.

예제

#include <iostream>
#include <type_traits>
#include <utility>
struct Foo { int n; };
int main()
{
    std::cout << std::boolalpha
              << "Foo is trivially copy-assignable? "
              << std::is_trivially_copy_assignable<Foo>::value << '\n'
              << "int[2] is copy-assignable? "
              << std::is_copy_assignable<int[2]>::value << '\n'
              << "int is nothrow copy-assignable? "
              << std::is_nothrow_copy_assignable<int>::value << '\n';
}

출력:

Foo is trivially copy-assignable? true
int[2] is copy-assignable? false
int is nothrow copy-assignable? true

결함 보고서

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

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

참고 항목

특정 인자에 대한 할당 연산자를 가지는지 확인
(클래스 템플릿)
이동 할당 연산자를 가지는지 확인
(클래스 템플릿)