Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Boost.Any vs. Boost.Variant

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.

like image 724
the_drow Avatar asked Sep 02 '09 08:09

the_drow


People also ask

What is boost any?

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.

What is boost variant?

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 .

How do I get the boost variant value?

You have to use boost::get<type>(variant) to get the value from a variant. Show activity on this post.


1 Answers

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.)

like image 171
drby Avatar answered Sep 21 '22 17:09

drby