zoukankan      html  css  js  c++  java
  • 分析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

    至于这些判断如何实现的,似乎比较复杂,暂时还没有分析清楚。。。
  • 相关阅读:
    P3146 [USACO16OPEN]248
    P2590 [ZJOI2008]树的统计
    P3379 【模板】最近公共祖先(LCA)
    P2253 好一个一中腰鼓!
    数组中出现次数超过一半的数字
    字符串的排列
    二叉搜索树与双向链表
    二叉搜索树的后序遍历序列
    从上往下打印二叉树
    顺时针打印矩阵
  • 原文地址:https://www.cnblogs.com/cutepig/p/1426682.html
Copyright © 2011-2022 走看看