c++c++11template-meta-programmingboost-mp11

Unnest Boost Mp11 list


Using Boost Mp11, I can create a nested mp_list as

#include <boost/mp11/list.hpp>
#include <boost/mp11/algorithm.hpp>

namespace mp11 = boost::mp11;

using num_types = mp11::mp_list<int, float, double>;

template <typename T>
using object_types = mp11::mp_list<std::vector<T>, std::list<T>>;

using all_types = mp11::mp_transform<object_types, num_types>;

If I'm not mistaken, this gives something like

mp11::mp_list<
  mp11::mp_list< std::vector<int>, std::list<int> >,
  mp11::mp_list< std::vector<float>, std::list<float> >,
  mp11::mp_list< std::vector<double>, std::list<double> >
>

Now I would like to eliminate the nesting to give something like

mp11::mp_list< std::vector<int>, std::list<int>, std::vector<float>, ... >

Unfortunately, I cannot figure out how to achieve this.


Solution

  • I'm sorry for the noise. I was able to figure out the answer to my question myself and it is fairly straightforward:

    using all_types_2 = mp11::mp_apply<mp11::mp_append, all_types>;
    

    does the job.