lundi 20 janvier 2020

How to Combine and Remove duplicates from MPL vector within an MPL vector of objects

Using GCC 4.8, c++11, for all types within the boost::mpl::vec called testers, that define VEC, I am trying to combine them all into single unique vec, ie, boost::mpl::vector, but recieving compiler error:

error: ‘type’ is not a member of ‘Filter<mpl_::arg<1> >

Code:

#include <boost/mpl/size.hpp>
#include <boost/type.hpp>
#include <boost/mpl/vector.hpp>
#include <boost/mpl/push_back.hpp>
#include <boost/mpl/for_each.hpp>
#include <boost/mpl/copy.hpp>
#include <boost/mpl/transform.hpp>

struct Base{};
struct A : public Base {};
struct B : public Base {};
struct C : public Base {};

struct TEST 
{
 typedef boost::mpl::vector<A,B> VEC;
};
struct TEST2
{
 //no VEC
};
struct TEST3
{
 typedef boost::mpl::vector<A,C> VEC;
};

typedef boost::mpl::vector<TEST,TEST2,TEST3> testers;

//for all types in testers that define VEC, combine them all into single unique 
// boost::mpl::vector<A,B,C>
//attempt
template< class... >
using void_t = void;

template <typename, typename = void>
struct HasVec : std::false_type
{
typedef typename boost::mpl::vector<> type;
};

template <typename T>
struct HasVec<T, void_t<decltype(T::VEC)>> : 
std::is_convertible<decltype(T::VEC), boost::mpl::vector<Base>>
{
 typedef typename boost::mpl::copy<typename T::VEC,
                                  boost::mpl::back_inserter<boost::mpl::vector<> >
                                  >::type type;
};

template<typename Tester>
struct Filter
{
    using type = HasVec<Tester>::type;
};


typedef typename boost::mpl::transform<testers,Filter<boost::mpl::_1>::type>::type Unique;

Aucun commentaire:

Enregistrer un commentaire