Opened 9 years ago

Closed 5 years ago

#8554 closed Bugs (fixed)

make_variant_over requires Extensible Sequence

Reported by: Darryl Green <darryl.green@…> Owned by: Antony Polukhin
Milestone: Boost 1.65.0 Component: variant
Version: Boost 1.53.0 Severity: Problem
Keywords: Cc:

Description

Variant tries to perform operations not supported by a Forward Sequence on the sequence provided to make_variant_over.

Conversely the type of variant<T>::types appears to be an Extensible Sequence which means:

Can fix by amending docs to specify that sequences used must be Extensible Sequences (needs both changes as motivation for composing via joint_view was to avoid applying operations requiring Extensible Sequence to variant<T>::types)

or

Can fix by composing an Extensible Sequence in make_variant_over - something like:

typedef boost::mpl::vector<> empty; typedef boost::mpl::insert_range<empty, boost::mpl::end<empty>::type, Sequence>::type ExtensibleSequence;

The following example shows the issue

#include <string> #include <boost/variant.hpp> #include <boost/mpl/joint_view.hpp> #include <boost/mpl/insert_range.hpp>

typedef boost::variant<int> v1; typedef boost::variant<std::string> v2; typedef boost::make_variant_over<boost::mpl::joint_view<v1::types, v2::types>::type>::type v3; FAILS - requires Extensible Sequence typedef boost::variant<int, std::string> v3; OK (obviously) typedef boost::make_variant_over<boost::mpl::insert_range<v1::types, boost::mpl::end<v1::types>::type, v2::types::type>::type>::type v3; OK (so types is probably an Extensible Sequence as insert_range works on it...)

int main(int argc, char *argv[]) {

v1 a = 1; v2 b = "2"; v3 c = a; return boost::get<int>(c);

}

Change History (4)

comment:1 by Darryl Green <darryl.green@…>, 9 years ago

Sorry about formatting - try this....

// possible "fix" to apply in make_variant_over
typedef boost::mpl::vector<> empty; typedef boost::mpl::insert_range<empty, boost::mpl::end<empty>::type, Sequence>::type ExtensibleSequence;

// example
#include <string>
#include <boost/variant.hpp>
#include <boost/mpl/joint_view.hpp>
#include <boost/mpl/insert_range.hpp>


typedef boost::variant<int> v1;
typedef boost::variant<std::string> v2;
typedef boost::make_variant_over<boost::mpl::joint_view<v1::types, v2::types>::type>::type v3; // FAILS - requires Extensible Sequence
//typedef boost::variant<int, std::string> v3; // OK (obviously)
//typedef boost::make_variant_over<boost::mpl::insert_range<v1::types, //boost::mpl::end<v1::types>::type, v2::types::type>::type>::type v3; // OK (so types is probably an Extensible Sequence as insert_range works on it...)


int main(int argc, char *argv[])
{
        v1 a = 1;
        v2 b = "2";
        v3 c = a;
        return boost::get<int>(c);
}

comment:2 by Antony Polukhin, 5 years ago

Milestone: To Be DeterminedBoost 1.65.0
Owner: changed from ebf to Antony Polukhin
Status: newassigned

comment:3 by Antony Polukhin, 5 years ago

Fixed by Mikhail Maximov in PR35.

comment:4 by Antony Polukhin, 5 years ago

Resolution: fixed
Status: assignedclosed
Note: See TracTickets for help on using tickets.