<type_traits>頭文件中提供了C++ STL的std::is_move_constructible模板。 C++ STL的std::is_move_constructible模板用於檢查T是否可移動構造(可以從其類型的右值引用構造)。它返回布爾值true或false。
頭文件:
#include<type_traits>
模板類別:
template< class T > struct is_move_convertible;
用法:
std::is_move_constructible< datatype >::value << '\n'
參數:模板std::is_move_constructible接受單個參數T(特質類)以檢查T是否為可移動構造類型。
返回值:
- True:如果給定的數據類型T為is_move_constructible。
- False:如果給定的數據類型T不是is_move_constructible。
下麵是演示std::is_move_constructible的程序:
程序:
// C++ program to illustrate
// std::is_move_constructible
#include <bits/stdc++.h>
#include <type_traits>
using namespace std;
// Declare structures
struct B {
};
struct A {
A& operator=(A&) = delete;
};
class C {
int n;
C(C&&) = default;
};
class D {
D(const D&) {}
};
// Driver Code
int main()
{
cout << boolalpha;
// Check if char is move constructible or not
cout << "char:"
<< is_move_constructible<char>::value
<< endl;
// Check if struct A is move constructible or not
cout << "struct A:"
<< is_move_constructible<A>::value
<< endl;
// Check if struct B is move constructible or not
cout << "struct B:"
<< is_move_constructible<B>::value
<< endl;
// Check if class C is move constructible or not
cout << "class C:"
<< is_move_constructible<C>::value
<< endl;
// Check if class D is move constructible or not
cout << "class D:"
<< is_move_constructible<D>::value
<< endl;
return 0;
}
輸出:
char:true struct A:true struct B:true class C:false class D:false
參考: http://www.cplusplus.com/reference/type_traits/is_move_constructible/
相關用法
- C語言 strtok()、strtok_r()用法及代碼示例
- C語言 memset()用法及代碼示例
- C++ std::mismatch()用法及代碼示例
- C++ wcscpy()用法及代碼示例
- C++ wcscmp()用法及代碼示例
- C++ set_symmetric_difference用法及代碼示例
- C++ ratio_equal()用法及代碼示例
- C++ std::equal_to用法及代碼示例
- C++ quick_exit()用法及代碼示例
- C++ multiset lower_bound()用法及代碼示例
- C++ multiset upper_bound()用法及代碼示例
- C++ multiset max_size()用法及代碼示例
- C++ forward_list max_size()用法及代碼示例
- C++ std::allocator()用法及代碼示例
- C++ array data()用法及代碼示例
- C++ multiset size()用法及代碼示例
- C++ ratio_not_equal()用法及代碼示例
注:本文由純淨天空篩選整理自bansal_rtk_大神的英文原創作品 std::is_move_constructible in C++ with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。