boost-variant

boost::variant - why is “const char*” converted to “bool”?

时光总嘲笑我的痴心妄想 提交于 2019-11-26 21:29:53
问题 I have declared a boost::variant which accepts three types: string , bool and int . The following code is showing that my variant accepts const char* and converts it to bool . Is it a normal behavior for boost::variant to accept and convert types not on its list? #include <iostream> #include "boost/variant/variant.hpp" #include "boost/variant/apply_visitor.hpp" using namespace std; using namespace boost; typedef variant<string, bool, int> MyVariant; class TestVariant : public boost::static

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

会有一股神秘感。 提交于 2019-11-26 18:51:26
问题 How do variant and any from the boost library work internally? In a project I am working on, I currently use a tagged union. I want to use something else, because unions in C++ don't let you use objects with constructors, destructors or overloaded assignment operators. I queried the size of any and variant, and did some experiments with them. In my platform, variant takes the size of its longest possible type plus 8 bytes: I think it my just be 8 bytes o type information and the rest being