I read the documentation on visit_each, but can’t really see what exactly it does, as well as the general use for it, if every user has to overload it anyways. Someone care to enlighten me?
Edit: Maybe I’m just so confused because the following is the whole content of <boost/visit_each.hpp> and I just don’t see any “magic” there to “visit each subobject”:
namespace boost {
template<typename Visitor, typename T>
inline void visit_each(Visitor& visitor, const T& t, long)
{
visitor(t);
}
template<typename Visitor, typename T>
inline void visit_each(Visitor& visitor, const T& t)
{
visit_each(visitor, t, 0);
}
}
Maybe someone can give me a concrete example of how this is supposed to look like / work?
I suspect the important part of that documentation is this line: “Library authors will be expected to add additional overloads that specialize the T argument for their classes, so that subobjects can be visited.” In other words, there is no general use for it, it is just a common name for any visitor-based introspection mechanism. The way it is implemented, something will happen for all types, whether their writers were aware of its existance or not, so you don’t get a compile-time failure.
It doesn’t seem overly useful to me… practically speaking, it is just an internal function of the boost signals library, but I suppose if you’re using that library anyhow specializing
visit_eachon your own types wouldn’t hurt.They mention finding
signals::trackableobjects. So presumably, they have provided a couple specializations for their own types within the signals library. Then they have ais_trackablefunctor. Or something similar.The key thing is that
visit_eachitself doesn’t do any magic, except provide a way for a call tovisit_eachto not fail to compile on an unrecognized type.