• 分析boost::function识别输入参数类型


    能识别四种类型:函数指针,函数对象,成员指针,函数对象的reference
    主要在这个get_function_tag类中。

     1
     2
     3// Tags used to decide between different types of functions
     4      struct function_ptr_tag {};
     5      struct function_obj_tag {};
     6      struct member_ptr_tag {};
     7      struct function_obj_ref_tag {};
     8
     9      template<typename F>
    10      class get_function_tag
    11      {
    12        typedef typename mpl::if_c<(is_pointer<F>::value),
    13                                   function_ptr_tag,
    14                                   function_obj_tag>::type ptr_or_obj_tag;
    15
    16        typedef typename mpl::if_c<(is_member_pointer<F>::value),
    17                                   member_ptr_tag,
    18                                   ptr_or_obj_tag>::type ptr_or_obj_or_mem_tag;
    19
    20        typedef typename mpl::if_c<(is_reference_wrapper<F>::value),
    21                                   function_obj_ref_tag,
    22                                   ptr_or_obj_or_mem_tag>::type or_ref_tag;
    23
    24      public:
    25        typedef or_ref_tag type;
    26      }
    ;
    27

    首先用L20 is_reference_wrapper识别出是否function_obj_ref_tag。如果不是,则到L16,看是否member_ptr判断是否member_ptr_tag,如果不是,则到L12,再看看是否is_pointer,如果是则为function_ptr,否则为function_obj

    至于这些判断如何实现的,似乎比较复杂,暂时还没有分析清楚。。。
  • 相关阅读:
    JS设计模式之----单例模式
    回流(reflow)与重绘(repaint)
    React native 图标使用
    JS常用几种存储方式的使用规则与各自特征
    Vue
    Promise 一自我总结
    三栏布局 && 两栏布局
    linux限制用户目录
    wireshark 抓包过滤
    python之tomcat自动化备份,更新
  • 原文地址:https://www.cnblogs.com/cutepig/p/1426682.html
Copyright © 2020-2023  润新知