Modify

Opened 4 years ago

Last modified 2 months ago

#8554 assigned Bugs

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 (3)

comment:1 Changed 4 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 2 months ago by Antony Polukhin

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

comment:3 Changed 2 months ago by Antony Polukhin

Fixed by Mikhail Maximov in PR35.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as assigned The owner will remain Antony Polukhin.

Add Comment


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

 
Note: See TracTickets for help on using tickets.