Am struggling a lot to find how to do to use boost::any
to create a print function that can print any type using template first.
template <typename T>
struct printer {
void print(ostream& os, const boost::any& a);
};
I need to define first print()
.
i wish to have the real operator <<
for any, The idea is simple: attach to each any object an instance of class
printer<T>
with the suitable T and change this object when the value type of the any
changes.
A first technical problem is that the printer object depends on T whereas any is not (and should not be) a class template.
Please I really need a hand is for tonight or tomorrow I have a deadline for tomorrow but I wish to work on it tonight.
There is quite easy way to do this, described in "Beyond the C++ Standard Library: An Introduction to Boost":
and then you use
any_out
instead ofboost::any
.