
C++11 offers non-restricted unions, which you can wrap in a class: class Wrapper { union { int64_t x1; // use better names than these... uint64_t x2; double x3; std::string x4; } m_u; public: explicit Wrapper(int64_t x1) { m_u.x1 = x1; } // etc.... // You'll also need some clever getters }; On Feb 17, 2015 6:00 AM, "Ben Pope" <benpope81@gmail.com> wrote:
On Tuesday, February 17, 2015 12:34 PM, U.Mutlu wrote:
Hi, I need to have a std::vector in my program, but it's type will be known only when it runs, ie. the type will be provided via a program param. The possible types are limited to these: int64_t, uint64_t, double, std::string. Is there a solution in boost or C++11 for this kind of problem?
Perhaps: std::vector<boost::variant<int64_t, uint64_t, double, std::string>>
http://www.boost.org/doc/libs/1_57_0/doc/html/variant.html
Ben
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users