Boost logo

Boost :

Subject: Re: [boost] [review][variant2] visit needs better user documentation
From: Peter Dimov (pdimov_at_[hidden])
Date: 2019-04-06 15:51:50

Larry Evans wrote:
> I only drew that conclusion because the number of args seems the only
> difference between the test that compiles OK and the one that doesn't. The
> code was copy&pasted from:
> and the function object there only accepts `int` as it's first argument.
> So, does that compile because any of the alternative types can be
> converted to `int`?


> Hmmm. Changed the all types of the lamba args to auto and it still fails
> to compile :( Why is that?

If we're talking about this program:

#include <boost/variant2/variant.hpp>
#include <string>

using namespace boost::variant2;

int main()
    variant<int, float, double, char, std::string> v1( 1 );
    variant<int, float, double, char, std::string> const v2( 3.14f );
    variant<int, float, double, char, std::string> v3( 6.28 );
    variant<int, float, double, char, std::string> const v4( 'A' );
    variant<int, float, double, char, std::string> const v5( "xxx" );

    visit( []( auto x1, auto x2, auto x3, auto x4, auto x5 ){}, v1, v2, v3,
v4, v5 );

it compiles with g++/clang++ -std=c++14, and doesn't with -std=c++11. It
also doesn't compile on VS2017 but compiles on VS2019. That's because the
unlimited argument implementation is disabled on C++11 or VS2017 here:

and, you're right, the workaround only supports up to four arguments.

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