4 ms·
I did not have a good experience with boost::variant ... Compile times increased drastically, compiler error messages became enormous and garbled with templates
by n00b101 10y ago
I did not have a good experience with boost::variant ... Compile times increased drastically, compiler error messages became enormous and garbled with templates, syntax was onerous in places (e.g. "make_recursive_variant"), and identification of types is based on arbitrary index value that is risky to rely on (which() method). I ended up refactoring the whole thing, removing boost::variant and just using the traditional visitor pattern. The only advantage boost::variant really has over traditional C++ visitor pattern is that boost static_visitor functions can have a non-void return type ... Being able to directly return a value in the visitor functions is admittedly very convenient, but the other issues negate this convenience.
- meetingcpp 10y agoboost::variant is 12 years old, the std::variant version is not based on the actual design nor is it a copy of the boost implementation. The interface is very similar, but the implementation is ofc using C++17 and not C++03.
- rleigh 10y agoThe boost implementation is certainly showing its age at this point, as is mpl, now we have variadic templates. Are there any C++14 variant implementations compatible with boost::variant and std::variant which are based on variadic templates? I'd love to move to a more modern implementation if possible.