分析boostfunction识别输入参数类型.
能识别四种类型:函数指针,函数对象,成员指针,函数对象的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
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
至于这些判断如何实现的,似乎比较复杂,暂时还没有分析清楚。。。