<type_traits>頭文件中提供了C++ STL的std::is_member_pointer模板。 C++ STL的std::is_member_pointer模板用於檢查T是否是指向非靜態成員的指針。如果T是指向非靜態成員類型的指針,則返回布爾值true,否則返回false。
頭文件:
#include<type_traits>
模板類別:
template<class T> struct is_member_pointer :std::integral_constant < bool, is_member_object_pointer<T>::value || is_member_function_pointer<T>::value> {};
用法:
std::is_member_pointer::value
參數:模板std::is_member_pointer接受單個參數T(Trait類),以檢查T是否是指向非靜態成員的指針。
返回值:該模板返回一個布爾變量,如下所示:
- True:如果類型T是指向非靜態成員的指針。
- False:如果類型T不是指向非靜態成員的指針。
下麵是說明C /C++中的std::is_member_pointer模板的程序:
程序:
// C++ program to illustrate
// std::is_member_pointer
#include <bits/stdc++.h>
#include <type_traits>
using namespace std;
// Driver Code
int main()
{
// Empty Class GFG
class GFG {
};
// Check if GFG::* is a member
// pointer or not
bool a = is_member_pointer<int(GFG::*)>::value;
if (a) {
cout << "GFG::* is a Member Pointer!"
<< endl;
}
else {
cout << "GFG::* is not a Member Pointer!"
<< endl;
}
// Check if int is a member
// pointer or not
a = is_member_pointer<int(int)>::value;
if (a) {
cout << "int is a Member Pointer!"
<< endl;
}
else {
cout << "int is not a Member Pointer!"
<< endl;
}
return 0;
}
輸出:
GFG::* is a Member Pointer! int is not a Member Pointer!
參考: http://www.cplusplus.com/reference/type_traits/is_member_pointer/
相關用法
- 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_member_pointer in C++ with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。