Boost logo

Boost :

Subject: Re: [boost] [variant] Breaking change introduced by variadic support
From: Agustín K-ballo Bergé (kaballo86_at_[hidden])
Date: 2014-01-20 16:10:24

On 18/01/2014 02:32 p.m., Antony Polukhin wrote:
> 2014/1/18 Agustín K-ballo Bergé <kaballo86_at_[hidden]>
>> The recent changes to introduce variadic support to `variant` introduce
>> breaking changes in the documented macros. When variadic support is
>> detected, `BOOST_VARIANT_LIMIT_TYPES` is not defined and
>> `BOOST_VARIANT_ENUM_[SHIFTED_]PARAMS` uses variadic templates instead of
>> enumerating parameters.
>> This is a breaking change in the documented interface, and one that
>> requires all but the simplest use cases to be rewritten. For instance, this
>> breaks _Boost.Spirit_ support of `variant` (
>> boost/ticket/9238), requiring two different implementations to be
>> provided.

While trying to make _Boost.Spirit_ work after the breaking changes, I
found a problem with the following snippet:

     #include <boost/variant.hpp>
     #include <boost/mpl/bool.hpp>

     template <typename T>
     struct is_container : boost::mpl::false_ {};

     template <typename T>
     struct is_container<boost::variant<T>> : is_container<T> {};

     template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
     struct is_container<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>>
       : boost::mpl::bool_<is_container<T0>::value
// #13

     int main()
         is_container<boost::variant<double, int>>::value;

If I understand correctly, this should work for both the variadic and
non-variadic cases. However, trying this with both MSVC2013 and NovCTP13
gives the following error:

> main.cpp(13): error C2976: 'boost::variant' : too few template arguments

The code works fine for GCC4.8.2 (both for C++03 and C++11), and it
works with Clang 3.3 too although it does not use the variadic version
(why?). Is this a bug with MSVC, or did I do something wrong? If the
former, I would suggest sticking with the non-variadic approach for
MSVC, since this seems to be a pretty basic use case. Also, feel free to
use the previous code as a base for a regression test.


Agustín K-ballo Bergé.-

Boost list run by bdawes at, gregod at, cpdaniel at, john at