I'm having trouble choosing between Boost.Any and Boost.Variant.
When should I use each one?
What are the advantages and disadvantages of each?
I am basically looking to store some states from external sources.
The boost::any class (based on the class of the same name described in "Valued Conversions" by Kevlin Henney, C++ Report 12(7), July/August 2000) is a variant value type based on the second category. It supports copying of any value type and safe checked extraction of that value strictly against its type.
boost::variant is defined in boost/variant. hpp . Because boost::variant is a template, at least one parameter must be specified. One or more template parameters specify the supported types. In Example 24.1, v can store values of type double , char , or std::string .
You have to use boost::get<type>(variant) to get the value from a variant. Show activity on this post.
Have you looked at the comparison in the variant library already?
(Not sure what states from external sources are, so it's kind of hard to say what's more appropriate for you.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With