std::is_member_function_pointer

定义于头文件 <type_traits>
template< class T >
struct is_member_function_pointer;
(C++11 起)

检查 T 是否为非静态成员函数指针。若 T 为非静态成员函数指针类型,则提供等于 true 的成员常量 value 。否则, value 等于 false

目录

模板形参

T - 要检查的类型

辅助变量模板

template< class T >
inline constexpr bool is_member_function_pointer_v = is_member_function_pointer<T>::value;
(C++17 起)

继承自 std::integral_constant

成员常量

value
[静态]
T 是成员函数指针类型则为 true ,否则为 false
(公开静态成员常量)

成员函数

operator bool
转换对象为 bool ,返回 value
(公开成员函数)
operator()
(C++14)
返回 value
(公开成员函数)

成员类型

类型 定义
value_type bool
type std::integral_constant<bool, value>

可能的实现

template< class T >
struct is_member_function_pointer_helper : std::false_type {};
 
template< class T, class U>
struct is_member_function_pointer_helper<T U::*> : std::is_function<T> {};
 
template< class T >
struct is_member_function_pointer : is_member_function_pointer_helper< std::remove_cv_t<T> > {};

示例

#include <type_traits>
 
class A {
public:
    void member() { }
};
 
int main()
{
    // 在编译时失败,若 A::member 是数据成员而非函数
    static_assert(std::is_member_function_pointer<decltype(&A::member)>::value,
                  "A::member is not a member function."); 
}


参阅

(C++11)
检查类型是否为指针类型
(类模板)
检查类型是否为指向非静态成员对象的指针
(类模板)
检查类型是否为指向非静态成员函数或对象的指针类型
(类模板)

版本历史

  • (当前 | 先前 2017年11月17日 (五) 04:53Fruderica讨论 | 贡献 . . (1,627字节) (+2). . (形参/辅助) (撤销)
  • 当前 | 先前 2017年7月25日 (二) 06:27Fruderica讨论 | 贡献. . (1,625字节) (-303). . (撤销)
  • 当前 | 先前 2014年10月26日 (日) 18:14P12bot讨论 | 贡献 . . (1,928字节) (0). . (Fix some translations) (撤销)
  • 当前 | 先前 2013年7月2日 (二) 11:41P12bot讨论 | 贡献 . . (1,928字节) (-99). . (Use {{lc}}. Update links. Various fixes.) (撤销)
  • 当前 | 先前 2012年11月2日 (五) 16:19P12bot讨论 | 贡献 . . (2,027字节) (+353). . (r2.7.3) (机器人添加:de, en, es, fr, it, ja, pt, ru) (撤销)
  • 当前 | 先前 2012年10月27日 (六) 11:40P12讨论 | 贡献 . . (1,674字节) (0). . (1个修订: Translate from the English version) (撤销)
  • 当前 | 先前 2012年10月26日 (五) 06:00TranslationBot讨论 | 贡献. . (1,674字节) (-23). . (Translated from the English version using Google Translate) (撤销)
  • 当前 | 先前 2012年10月26日 (五) 03:33P12讨论 | 贡献 . . (1,697字节) (0). . (1个修订: Translate from the English version) (撤销)
  • 当前 | 先前) 2012年10月25日 (四) 12:00TranslationBot讨论 | 贡献. . (1,697字节) (+1,697). . (Translated from the English version using Google Translate)