I'm using the library boost::variant
to store a large number of types. As the number of type is growing, I will soon reach the limit of 20 types. In the documentation it seems possible to define the variant using a mpl::vector
, which allows more than 20 types (up to 50 if I'm correct). I tried to replace my variant definition like this:
#include <boost/variant.hpp>
#include <boost/mpl/vector.hpp>
typedef boost::mpl::vector<
float,
math::float2,
math::float3,
relative_point<1>,
relative_point<2>,
relative_point<3>,
std::string,
color,
group,
dictionnary,
reference,
line,
strip,
text,
font
> variant_mpl_vec;
typedef boost::make_variant_over<variant_mpl_vec>::type data_type;
// This is the old definition
/*typedef boost::variant<
float,
math::float2,
math::float3,
relative_point<1>,
relative_point<2>,
relative_point<3>,
std::string,
color,
group,
dictionnary,
reference,
line,
strip,
text,
font
> data_type;*/
I'm putting directly my code. Most of types are structures containing very few data.
When compiling, I got a strange:
error: no matching function for call to ‘boost::detail::variant::make_initializer_node::apply<boost::mpl::pair< ... and lots more ...
Previous variant definition was working fine, so I'm surprised my replacement doesn't work. I'm new to mpl
so maybe I'm missing something - but can't find what ! Am'I doing well ?
Thanks in advance.
Variant type definition is correct, the problem was due to a generic function in the program taking an arbitrary variant as parameter. Indeed, make_variant_over<mpl::vector<T0, T1, ...>>
behaves like variant<T0, T1, ...>
but is not the same type: it is a variant<over_sequence<vector<T0, T1, ...>>>
(so T0 corresponds to over_sequence<vector<T0, T1, ...>>
.