4

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.

Luc Touraille
  • 79,925
  • 15
  • 92
  • 137
neodelphi
  • 2,706
  • 1
  • 15
  • 22
  • Though with simplified version, the code in the question could be compiled on [ideone](http://ideone.com/Sgx02). This [document](http://www.boost.org/doc/libs/1_47_0/doc/html/variant/tutorial.html#variant.tutorial.over-sequence) says: _due to standard conformance issues in several compilers, `make_variant_over` is not universally available. On these compilers the library indicates its lack of support for the syntax via the definition of the preprocessor symbol `BOOST_VARIANT_NO_TYPE_SEQUENCE_SUPPORT`._ So I'd suggest checking `BOOST_VARIANT_NO_TYPE_SEQUENCE_SUPPORT`'s value. – Ise Wisteria Jul 21 '11 at 10:55
  • Advanced in the problem. It seems this is not a problem due to the definition of the variant, but a generic function taking a variant as input `boost::variant`. This function sees `T0` as `boost::detail::variant::over_sequence >`, can't understand why for the moment. – neodelphi Jul 21 '11 at 11:41

1 Answers1

1

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, ...>>.

neodelphi
  • 2,706
  • 1
  • 15
  • 22