Modify

Opened 5 years ago

Closed 8 weeks 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);

}

Attachments (0)

Change History (4)

comment:1 Changed 5 years ago by Darryl Green <darryl.green@…>

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 Changed 4 months ago by Antony Polukhin

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

comment:3 Changed 4 months ago by Antony Polukhin

Fixed by Mikhail Maximov in PR35.

comment:4 Changed 8 weeks ago by Antony Polukhin

Resolution: fixed
Status: assignedclosed

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Antony Polukhin.
The resolution will be deleted.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.