, : ", , T , ". , , , . , , - , , , .
, ... , , , , visit_each , 't .
signals::trackable. , , . is_trackable. - .
struct trackable { };
struct Introspective {
int a;
double b;
trackable c;
};
struct NotIntrospective {
int a;
double b;
trackable c;
};
template<typename Visitor, typename T>
inline void visit_each(Visitor& visitor, const T& t, long) {
visitor(t);
}
template<typename Visitor>
inline void visit_each(Visitor& visitor, const Introspective& t, int) {
visitor(t);
visit_each(visitor, t.a, 0);
visit_each(visitor, t.b, 0);
visit_each(visitor, t.c, 0);
}
struct is_trackable {
void operator()(const trackable&) {
}
template<typename T>
void operator()(const T&) { }
}
int main() {
Introspective a;
NotIntrospective b;
trackable c;
visit_each(is_trackable(), a, 0);
visit_each(is_trackable(), b, 0);
visit_each(is_trackable(), c, 0);
}
, visit_each , visit_each, .