首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::is_move_assignable

Defined in header <type_traits>

template< class T > struct is_move_assignable;

(1)

(since C++11)

template< class T > struct is_trivially_move_assignable;

(2)

(since C++11)

template< class T > struct is_nothrow_move_assignable;

(3)

(since C++11)

1%29T不是可引用的类型%28i。E.,可能是cv-符合条件的void类的函数类型。简历-限定符-seq或者是参-限定符%29,提供成员常量。value等于false否则,提供成员常量。value等于std::is_assignable<T&, T&&>::value...

2%29与1%29相同,但使用std::is_trivially_assignable<T&, T&&>

3%29与1%29相同,但使用std::is_nothrow_assignable<T&, T&&>

T为完整类型,%28可能是cv-合格%29void,或者一系列未知的界限。否则,行为就没有定义。

辅助变量模板

template< class T > inline constexpr bool is_move_assignable_v = is_move_assignable<T>::value;

(since C++17)

template< class T > inline constexpr bool is_trivially_move_assignable_v = is_trivially_move_assignable<T>::value;

(since C++17)

template< class T > inline constexpr bool is_nothrow_move_assignable_v = is_nothrow_move_assignable<T>::value;

(since C++17)

继承自STD:积分[医]常量

成员常数

value static

true if T is move-assignable, false otherwise (public static member constant)

成员函数

operator bool

converts the object to bool, returns value (public member function)

operator() (C++14)

returns value (public member function)

成员类型

Type

Definition

value_type

bool

type

std::integral_constant<bool, value>

可能的实施

模板<class T>结构是[医]移动[医]可分配:std::is[医]可分配<type Name std::add[医]洛值[医]参照系<T>*类型,输入名称STD::Add[医]r值[医]参照系<T>*type>{};模板<class T>struct是[医]琐碎[医]移动[医]可分配:std::is[医]琐碎[医]可分配<type Name std::add[医]洛值[医]参照系<T>*类型,输入名称STD::Add[医]r值[医]参照系<T>*type>{};模板<class T>struct是[医]无抛[医]移动[医]可分配:std::is[医]无抛[医]可分配<type Name std::add[医]洛值[医]参照系<T>*类型,输入名称STD::Add[医]r值[医]参照系<T>*类型>{};

*。

注记

特质std::is_move_assignable不那么严格MoveAssignable因为它不检查赋值%28的结果类型,因此对于MoveAssignable类型,必须是T&%29,也不要求分配后的目标%27s值与分配之前的源%27s值等效。

类型不必实现移动赋值算子为了满足这一特点;见MoveAssignable关于细节。

二次

代码语言:javascript
复制
#include <iostream>
#include <string>
#include <type_traits>
struct Foo { int n; };
struct NoMove {
    // prevents implicit declaration of default move assignment operator
    // however, the class is still move-assignable because its
    // copy assignment operator can bind to an rvalue argument
    NoMove& operator=(const NoMove&) { return *this; }
};
int main() {
    std::cout << std::boolalpha
              << "std::string is nothrow move-assignable? "
              << std::is_nothrow_move_assignable<std::string>::value << '\n'
              << "int[2] is move-assignable? "
              << std::is_move_assignable<int[2]>::value << '\n'
              << "Foo is trivally move-assignable? "
              << std::is_trivially_move_assignable<Foo>::value << '\n';
 
    std::cout << std::boolalpha
              << "NoMove is move-assignable? "
              << std::is_move_assignable<NoMove>::value << '\n'
              << "NoMove is nothrow move-assignable? "
              << std::is_nothrow_move_assignable<NoMove>::value << '\n';
}

二次

产出:

二次

代码语言:javascript
复制
std::string is nothrow move-assignable? true
int[2] is move-assignable? false
Foo is trivially move-assignable? true
NoMove is move-assignable? true
NoMove is nothrow move-assignable? false

二次

另见

is_assignableis_trivially_assignableis_nothrow_assignable (C++11)(C++11)(C++11)

checks if a type has a assignment operator for a specific argument (class template)

is_copy_assignableis_trivially_copy_assignableis_nothrow_copy_assignable (C++11)(C++11)(C++11)

checks if a type has a copy assignment operator (class template)

代码语言:txt
复制
 © cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券