传入一个f,
1首先跑到Line12,
如果是ref_wrapper对象则跑到1.1,否则1.2
1.1 L20,拿到指针,直接调用 add_if_trackable,而该add_if_trackable
函数可以看到有多个重载,如果是Trackable的派生类,则会跑到L48,结束
1.2 L26,判断是否指针,如果不是,先转成指针L40,然后调用
add_if_trackable
。。。。
template<bool Cond> struct truth ...{};
2
3 // A visitor that adds each trackable object to a vector
4 class bound_objects_visitor ...{
5 public:
6 bound_objects_visitor(std::vector<const trackable*>& v) :
7 bound_objects(v)
8 ...{
9 }
10
11 template<typename T>
12 void operator()(const T& t) const //1.主函数
13 ...{
14 decode(t, 0);
15 }
16
17 private:
18 // decode() decides between a reference wrapper and anything else
19 template<typename T>
20 void decode(const reference_wrapper<T>& t, int) const //1.1.如果是ref_wrapper则跑这里,这里得到指针
21 ...{
22 add_if_trackable(t.get_pointer());
23 }
24
25 template<typename T>
26 void decode(const T& t, long) const //1.2.否则跑这里
27 ...{
28 typedef truth<(is_pointer<T>::value)> is_a_pointer;
29 maybe_get_pointer(t, is_a_pointer());
30 }
31
32 // maybe_get_pointer() decides between a pointer and a non-pointer
33 template<typename T>
34 void maybe_get_pointer(const T& t, truth<true>) const //1.2.1如果是pointer,直接调用
35 ...{
36 add_if_trackable(t);
37 }
38
39 template<typename T>
40 void maybe_get_pointer(const T& t, truth<false>) const //1.2.2不是pointer,转为指针
41 ...{
42 // Take the address of this object, because the object itself may be
43 // trackable
44 add_if_trackable(boost::addressof(t));
45 }
46
47 // add_if_trackable() adds trackable objects to the list of bound objects
48 inline void add_if_trackable(const trackable* b) const //1.2.1or2.1 是trackable
49 ...{
50 if (b) ...{
51 bound_objects.push_back(b);
52 }
53 }
54
55 inline void add_if_trackable(const void*) const //1.2.1or2.2不是trackable
56 ...{
57 }
58
59 template<typename R>
60 inline void add_if_trackable(R (*)()) const
61 ...{
62 }
63
64 template<typename R, typename T1>
65 inline void add_if_trackable(R (*)(T1)) const
66 ...{
67 }
68
69 template<typename R, typename T1, typename T2>
70 inline void add_if_trackable(R (*)(T1, T2)) const
71 ...{
72 }
73
74 template<typename R, typename T1, typename T2, typename T3>
75 inline void add_if_trackable(R (*)(T1, T2, T3)) const
76 ...{
77 }
78
79 template<typename R, typename T1, typename T2, typename T3, typename T4>
80 inline void add_if_trackable(R (*)(T1, T2, T3, T4)) const
81 ...{
82 }
83
84 template<typename R, typename T1, typename T2, typename T3, typename T4,
85 typename T5>
86 inline void add_if_trackable(R (*)(T1, T2, T3, T4, T5)) const
87 ...{
88 }
89
90 template<typename R, typename T1, typename T2, typename T3, typename T4,
91 typename T5, typename T6>
92 inline void add_if_trackable(R (*)(T1, T2, T3, T4, T5, T6)) const
93 ...{
94 }
95
96 template<typename R, typename T1, typename T2, typename T3, typename T4,
97 typename T5, typename T6, typename T7>
98 inline void add_if_trackable(R (*)(T1, T2, T3, T4, T5, T6, T7)) const
99 ...{
100 }
101
102 template<typename R, typename T1, typename T2, typename T3, typename T4,
103 typename T5, typename T6, typename T7, typename T8>
104 inline void add_if_trackable(R (*)(T1, T2, T3, T4, T5, T6, T7, T8)) const
105 ...{
106 }
107
108 template<typename R, typename T1, typename T2, typename T3, typename T4,
109 typename T5, typename T6, typename T7, typename T8, typename T9>
110 inline void
111 add_if_trackable(R (*)(T1, T2, T3, T4, T5, T6, T7, T8, T9)) const
112 ...{
113 }
114
115 template<typename R, typename T1, typename T2, typename T3, typename T4,
116 typename T5, typename T6, typename T7, typename T8, typename T9,
117 typename T10>
118 inline void
119 add_if_trackable(R (*)(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10)) const
120 ...{
121 }
122
123 std::vector<const trackable*>& bound_objects;
124 };
125