In an answer to this SO question:
What is the equivalent of boost::variant in the C++ standard library?
it is mentioned that boost::variant
and std::variant
differ somewhat.
- What are the differences, as far as someone using these classes is concerned?
- What motivation did the committee express to adopt
std::variant
with these differences? - What should I watch out for when coding with either of these, to maintain maximum compatibility with switching to the other one?
(the motivation is using boost::variant
in pre-C++17 code)
boost::variant
andboost::variant2
are two different libraries. The question is about the former, but it seems worth noting that the official documentation ofboost::variant2
states that it is API compatible withstd::variant
, with some provisos: boost.org/doc/libs/1_75_0/libs/variant2/doc/html/… . See also the Boost project listing at boost.org/doc/libs/1_75_0 – Octaviaoctavian