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

    至于这些判断如何实现的,似乎比较复杂,暂时还没有分析清楚。。。
  • 相关阅读:
    总结下目前维护团队中用到的一些技术和工具
    一次修改时间导致的ORACLE 实例崩溃
    ruby 用watir 登录 CU的代码
    最近好烦.真的好烦
    Lucene.Net学习
    项目上线了,心情好爽
    轻松掌握XMLHttpRequest对象[转]
    微软发布3款SQL Injection攻击检测工具
    Domino开发
    用在JavaScript的RequestHelper [转]
  • 原文地址:https://www.cnblogs.com/cutepig/p/1426682.html
Copyright © 2011-2022 走看看