How do boost::variant and boost::any work?

If you read the boost::any documentation they provide the source for the idea: http://www.two-sdg.demon.co.uk/curbralan/papers/ValuedConversions.pdf It’s basic information hiding, an essential C++ skill to have. Learn it! Since the highest voted answer here is totally incorrect, and I have my doubts that people will actually go look at the source to verify that fact, here’s a … Read more

How to print boost::any to a stream?

You could use boost::spirit::hold_any instead. It’s defined here: #include <boost/spirit/home/support/detail/hold_any.hpp> and is fully compatible with boost::any. This class has two differences if compared to boost::any: it utilizes the small object optimization idiom and a couple of other optimization tricks, making spirit::hold_any smaller and faster than boost::any it has the streaming operators (operator<<() and operator>>()) defined, … Read more