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

    至于这些判断如何实现的,似乎比较复杂,暂时还没有分析清楚。。。
  • 相关阅读:
    回调函数和表驱动法编程
    学会看datasheet W25Q128为例
    STM32 Makefile的一次bug解决过程
    STM32 一种参数检查用法介绍
    STM32 中断和事件
    STM32 OV2640将数据缓存至SRAM
    STM32 .ld链接文件分析及一次bug解决过程
    浅谈嵌入式软件设计
    STM32 Makefile的设置和工程管理
    [转]Linux下的lds链接脚本详解
  • 原文地址:https://www.cnblogs.com/cutepig/p/1426682.html
Copyright © 2011-2022 走看看