std::is_move_constructible, std::is_trivially_move_constructible, std::is_nothrow_move_constructible
来自cppreference.com
|
|
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
| Defined in header <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 起) |
检查一个类型是否是
2) MoveConstructible,即有一个可访问的显式或隐式的举动构造函数。如果符合要求,一个成员value等于true,否则value是false.Original:
Checks whether a type is
MoveConstructible, i.e. has an accessible explicit or implicit move constructor. If the requirement is met, a member constant value equal true is provided, otherwise value is false.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
同为1),但此举构造器的表达式不调用任何操作,是不平凡的.
3) Original:
Same as 1), but the move constructor expression does not call any operation that is not trivial.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
同为1),但这一举措的构造的表达noexcept.
Original:
Same as 1), but the move constructor expression is noexcept.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
目录 |
Inherited from std::integral_constant
Member constants
| value [静态的] </ SPAN></div></div>
|
true如果 T is move-constructible ,false其他方式 Original: true if T is move-constructible , false otherwise The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (公共静态成员常量) |
Member functions
| operator bool |
转换的对象bool,返回 value Original: converts the object to bool, returns value The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (公共成员函数) |
Member types
| 类型
Original: Type The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
Definition |
value_type
|
bool
|
type
|
std::integral_constant<bool, value> |
</div>
[编辑] 注释
移动构造函数通常noexcept,因为否则的话,他们是无法使用任何代码,提供了强大的异常保证.
Original:
Move constructors are usually noexcept, since otherwise they are unusable in any code that provides strong exception guarantee.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[编辑] 可能的实现
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> {}; |
[编辑] 为例
#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 }; 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'; }
Output:
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
[编辑] 另请参阅
| (C++11) (C++11) (C++11) |
检查如果一个类型有一个构造函数的具体参数 Original: checks if a type has a constructor for specific arguments The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (类模板) |
| 检查如果一个类型有一个默认的构造函数 Original: checks if a type has a default constructor The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (类模板) | |
| (C++11) (C++11) (C++11) |
一类的检查,如果有拷贝构造函数 Original: checks if a type has a copy constructor The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (类模板) |
| (C++11) |
获得一个右值引用的举动构造方法不抛出 Original: obtains an rvalue reference if the move constructor does not throw The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (函数模板) |