How to get the standard mpl sequence after folding

If I use boost :: mpl, consider the following code:

typedef fold<
  vector<long,float,long>
, set0<>
, insert<_1,_2>
>::type s;

BOOST_MPL_ASSERT_RELATION( size<s>::value, ==, 2 );

How can I turn it back on sinto a type t = boost::mpl::set<long,float>so that I can use ta partially specialized template function (in boost :: mpl :: set``) to select which element types are extracted and turned into std::tuple<long,float>. Is it something else

+2
source share
1 answer

. metafunction Unify, , , , .
, , .

    #include <boost/mpl/set.hpp>
    #include <boost/mpl/front.hpp>
    #include <boost/mpl/size.hpp>
    #include <boost/mpl/insert.hpp>
    #include <boost/mpl/erase_key.hpp>
    #include <tuple>

    template <template <class...> class OutSeqType,
              class Sequence,
              std::size_t nSeqSize,
              class ... Elements>
    struct Unify
    {
        typedef typename boost::mpl::front<Sequence>::type Next;
        typedef typename Unify<
            OutSeqType,
            typename boost::mpl::erase_key<Sequence, Next>::type,
            nSeqSize - 1, Next, Elements...>::type type;
    };

    template <template <class...> class OutSeqType,
              class Sequence,
              class ... Elements>
    struct Unify<OutSeqType, Sequence, 0ul, Elements...>
    {
        typedef OutSeqType<Elements...> type;
    };

    int main()
    {
        typedef boost::mpl::insert<
            boost::mpl::insert<
                boost::mpl::insert<
                    boost::mpl::set<>,
                    int>::type,
                float>::type,
            int*>::type Set;

        typedef Unify<
            std::tuple,
            Set,
            boost::mpl::size<Set>::type::value
            >::type Set2;

        //This compile error will print the type of Set2
        Set2::asdfl;
    }

- , pop_front set, erase_key. , . .

+1

All Articles