std::is_nothrow_move_constructible
STD::是[医]移动[医]可构造的,STD::is[医]琐碎[医]移动[医]可构造的,STD::is[医]无抛[医]移动[医]可构造
Defined in header | | |
---|---|---|
template< class T > struct is_move_constructible; | (1) | (since C++11) |
template< class T > struct is_trivially_move_constructible; | (2) | (since C++11) |
template< class T > struct is_nothrow_move_constructible; | (3) | (since C++11) |
1%29T不是可引用的类型%28i。E.,可能是cv-符合条件的void类的函数类型。简历-限定符-seq或者是参-限定符%29,提供成员常量。value等于false否则,提供成员常量。value等于std::is_constructible<T, T&&>::value...
2%29与%281%29相同,但使用std::is_trivially_constructible<T, T&&>...
3%29与%281%29相同,但使用std::is_nothrow_constructible<T, T&&>...
T
为完整类型,%28可能是cv-合格%29void
,或者一系列未知的界限。否则,行为就没有定义。
辅助变量模板
template< class T > inline constexpr bool is_move_constructible_v = is_move_constructible | | (since C++17) |
---|---|---|
template< class T > inline constexpr bool is_trivially_move_constructible_v = is_trivially_move_constructible<T>::value; | | (since C++17) |
template< class T > inline constexpr bool is_nothrow_move_constructible_v = is_nothrow_move_constructible<T>::value; | | (since C++17) |
继承自STD:积分[医]常量
成员常数
value static | true if T is move-constructible , 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[医]可构造<T,type Name std::add[医]r值[医]参照系<T>*类型>{};模板<class T>结构是[医]琐碎[医]移动[医]可构造性:std::is[医]琐碎[医]可构造<T,type Name std::add[医]r值[医]参照系<T>*类型>{};模板<class T>结构是[医]无抛[医]移动[医]可构造性:std::is[医]无抛[医]可构造<T,type Name std::add[医]r值[医]参照系<T>*类型>{};
*。
注记
类型,但不使用移动构造函数,而是使用可接受的复制构造函数。const T&
论点,满足std::is_move_constructible
...
Move构造函数通常为NoOPTION,因为否则它们在任何提供强异常保证的代码中都是不可用的。
在许多实现中,is_nothrow_move_constructible
还检查析构函数是否抛出,因为它有效。noexept(T(arg))
.同样适用于is_trivially_move_constructible
,在这些实现中,还要求析构函数是微不足道的:gcc bug 51452lwg第2116期...
例
二次
#include <iostream>
#include <type_traits>
struct Ex1 {
std::string str; // member has a non-trivial but non-throwing move ctor
};
struct Ex2 {
int n;
Ex2(Ex2&&) = default; // trivial and non-throwing
};
struct NoMove {
// prevents implicit declaration of default move constructor
// however, the class is still move-constructible because its
// copy constructor can bind to an rvalue argument
NoMove(const NoMove&) {}
};
int main() {
std::cout << std::boolalpha << "Ex1 is move-constructible? "
<< std::is_move_constructible<Ex1>::value << '\n'
<< "Ex1 is trivially move-constructible? "
<< std::is_trivially_move_constructible<Ex1>::value << '\n'
<< "Ex1 is nothrow move-constructible? "
<< std::is_nothrow_move_constructible<Ex1>::value << '\n'
<< "Ex2 is trivially move-constructible? "
<< std::is_trivially_move_constructible<Ex2>::value << '\n'
<< "Ex2 is nothrow move-constructible? "
<< std::is_nothrow_move_constructible<Ex2>::value << '\n';
std::cout << std::boolalpha
<< "NoMove is move-constructible? "
<< std::is_move_constructible<NoMove>::value << '\n'
<< "NoMove is nothrow move-constructible? "
<< std::is_nothrow_move_constructible<NoMove>::value << '\n';
}
二次
产出:
二次
Ex1 is move-constructible? true
Ex1 is trivially move-constructible? false
Ex1 is nothrow move-constructible? true
Ex2 is trivially move-constructible? true
Ex2 is nothrow move-constructible? true
NoMove is move-constructible? true
NoMove is nothrow move-constructible? false
二次
另见
is_constructibleis_trivially_constructibleis_nothrow_constructible (C++11)(C++11)(C++11) | checks if a type has a constructor for specific arguments (class template) |
---|---|
is_default_constructibleis_trivially_default_constructibleis_nothrow_default_constructible (C++11)(C++11)(C++11) | checks if a type has a default constructor (class template) |
is_copy_constructibleis_trivially_copy_constructibleis_nothrow_copy_constructible (C++11)(C++11)(C++11) | checks if a type has a copy constructor (class template) |
move_if_noexcept (C++11) | obtains an rvalue reference if the move constructor does not throw (function template) |
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。