I am looking for an alternative to C-style union. boost::variant is one such option. Is there anything in std C++ ?
union {
int i;
double d;
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
As several commenters said: No, there is no Boost Variant-alike in standard C++. Maybe in a few years there will be, but why wait–use Boost Variant today!
Edit (four years later, 2016): In C++17 there will be
std::variant. Similar but not identical toboost::variant. So when your compiler supports C++17, you will have a solution in the standard library.