Namespaces
Variants

std:: is_move_constructible, std:: is_trivially_move_constructible, std:: is_nothrow_move_constructible

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
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_move_constructible ;
(1) (C++11부터)
template < class T >
struct is_trivially_move_constructible ;
(2) (C++11부터)
template < class T >
struct is_nothrow_move_constructible ;
(3) (C++11부터)
타입 특성 멤버 상수 value 의 값
T 참조 가능 타입 인 경우 T 가 참조 가능 타입이 아닌 경우
(1) std:: is_constructible < T, T && > :: value false
(2) std:: is_trivially_constructible < T, T && > :: value
(3) std:: is_nothrow_constructible < T, T && > :: value

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

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

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

목차

헬퍼 변수 템플릿

template < class T >

inline constexpr bool is_move_constructible_v =

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

inline constexpr bool is_trivially_move_constructible_v =

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

inline constexpr bool is_nothrow_move_constructible_v =

is_nothrow_move_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_move_constructible :
    std::is_constructible<T, typename std::add_rvalue_reference<T>::type> {};
template<class T>
struct is_trivially_move_constructible :
    std::is_trivially_constructible<T, typename std::add_rvalue_reference<T>::type> {};
template<class T>
struct is_nothrow_move_constructible :
    std::is_nothrow_constructible<T, typename std::add_rvalue_reference<T>::type> {};

참고 사항

이동 생성자가 없지만 const T & 인자를 받는 복사 생성자를 가진 타입들은 std::is_move_constructible 를 만족합니다.

이동 생성자는 일반적으로 noexcept입니다, 그렇지 않으면 강력한 예외 보장을 제공하는 모든 코드에서 사용할 수 없기 때문입니다.

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

예제

#include <string>
#include <type_traits>
struct Ex1
{
    std::string str; // 멤버가 trivial하지 않지만 예외를 던지지 않는 이동 생성자를 가짐
};
static_assert(std::is_move_constructible_v<Ex1>);
static_assert(!std::is_trivially_move_constructible_v<Ex1>);
static_assert(std::is_nothrow_move_constructible_v<Ex1>);
struct Ex2
{
    int n;
    Ex2(Ex2&&) = default; // trivial하고 예외를 던지지 않음
};
static_assert(std::is_move_constructible_v<Ex2>);
static_assert(std::is_trivially_move_constructible_v<Ex2>);
static_assert(std::is_nothrow_move_constructible_v<Ex2>);
struct NoMove1
{
    // 기본 이동 생성자의 암시적 선언을 방지함;
    // 그러나 복사 생성자가 rvalue 인자에 바인딩할 수 있으므로
    // 클래스는 여전히 이동 생성 가능함
    NoMove1(const NoMove1&) {}
};
static_assert(std::is_move_constructible_v<NoMove1>);
static_assert(!std::is_trivially_move_constructible_v<NoMove1>);
static_assert(!std::is_nothrow_move_constructible_v<NoMove1>);
struct NoMove2
{
    // lvalue 참조가 rvalue 인자에 바인딩할 수 없으므로
    // 이동 생성 불가능
    NoMove2(NoMove2&) {}
};
static_assert(!std::is_move_constructible_v<NoMove2>);
static_assert(!std::is_trivially_move_constructible_v<NoMove2>);
static_assert(!std::is_nothrow_move_constructible_v<NoMove2>);
int main() {}

결함 보고서

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

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

참고 항목

특정 인수들에 대한 생성자가 있는지 확인합니다
(클래스 템플릿)
기본 생성자가 있는지 확인합니다
(클래스 템플릿)
복사 생성자가 있는지 확인합니다
(클래스 템플릿)
해당 타입의 객체가 이동 생성될 수 있음을 명시합니다
(컨셉)
(C++11)
인수를 xvalue로 변환합니다
(함수 템플릿)
이동 생성자가 예외를 던지지 않는 경우 인수를 xvalue로 변환합니다
(함수 템플릿)