I'm trying to provide a program a way to add new objects to a variant in a library but I'm encountering some cryptic errors.
#include <boost/mpl/copy.hpp>
#include <boost/mpl/joint_view.hpp>
#include <boost/mpl/list.hpp>
#include <boost/variant/variant.hpp>
struct InternalType1 {};
struct InternalType2 {};
template <typename LocalTypes>
struct Foo
{
typedef boost::mpl::list<
InternalType1,
InternalType2
> Types;
typename boost::make_variant_over<
typename boost::mpl::joint_view<
Types,
LocalTypes
>::type
>::type container_;
// typename boost::make_variant_over<
// typename boost::mpl::copy<
// LocalTypes,
// boost::mpl::back_inserter<Types>
// >::type
// >::type container_;
};
struct LocalType1 {};
struct LocalType2 {};
int main()
{
typedef boost::mpl::list<
LocalType1,
LocalType2
> Types;
Foo<Types> foo;
}
By using a mpl::joint_view
(which I assume if the most efficient way of achieving this), I get the following error:
/usr/local/include/boost/mpl/clear.hpp:29:7: error: implicit instantiation of undefined template
By uncommenting the other attempt, using mpl::copy
, and replacing it with the original, then the error changes:
/usr/local/include/boost/mpl/aux_/push_back_impl.hpp:40:9: error: no matching function for call to 'assertion_failed'
Which, interestingly, has the following comment:
// should be instantiated only in the context of 'has_push_back_impl';
// if you've got an assert here, you are requesting a 'push_back'
// specialization that doesn't exist.
Neither of these errors make any sense to me as, w/r/t the first, I don't see which templates are not complete and for the second, which push_back specialization I'm not using?
mpl::list
can't be used withpush_back
. You could useboost::mpl::front_inserter<Types>
or simply use ampl::vector
in yourTypes
typedef. – Anguishedmake_variant_over
.mpl::copy
frommpl::vector
s is the way if you ask me – Ulickjoint_view
not a feasible thing to do here? It says in the documentation formake_variant_over
that it requires an MPL Sequence. And then thejoint_view
docs state that joint_view is a Forward Sequence. So these two should be compatible, no? – Speculation