std::is_member_pointer
来自cppreference.com
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
在头文件 <type_traits> 中定义
|
||
template< class T > struct is_member_pointer; |
(C++11 起) | |
T
是指向非静态成员对象或一个非静态成员函数的指针,为会员提供恒定的value
等于true。对于任何其他类型,value
是false.原文:
If
T
is pointer to non-static member object or a pointer to non-static member function, provides the member constant value
equal true. For any other type, value
is false.目录 |
Inherited from std::integral_constant
Member constants
value [静态的]</div></div>
|
true如果 T is a member pointer type ,false其他方式 原文: true if T is a member pointer type , false otherwise (公共静态成员常量) |
Member functions
operator bool |
转换的对象bool,返回 value 原文: converts the object to bool, returns value (公共成员函数) |
Member types
类型
|
Definition |
value_type
|
bool
|
type
|
std::integral_constant<bool, value> |
</div>
[编辑] 可能的实现
template< class T > struct is_member_pointer_helper : std::false_type {}; template< class T, class U > struct is_member_pointer_helper<T U::*> : std::true_type {}; template< class T > struct is_member_pointer : is_member_pointer_helper<typename std::remove_cv<T>::type> {}; |
[编辑] 示例
本章尚未完成 原因:simplify |
#include <iostream> #include <type_traits> int main() { class cls {}; std::cout << (std::is_member_pointer<int(cls::*)>::value ? "T is member pointer" : "T is not a member pointer") << '\n'; std::cout << (std::is_member_pointer<int>::value ? "T is member pointer" : "T is not a member pointer") << '\n'; }
输出:
T is member pointer T is not a member pointer
[编辑] 另请参阅
检查是否是指针类型 (类模板) | |
(C++11) |
检查是否是一个指向非静态成员变量的指针类型 (类模板) |
(C++11) |
检查是否是指向非静态成员函数的指针类型 (类模板) |