The list of combinations of the same int type with the list of types mpl::vector<int, long> can be calculated by calling mpl::fold :
typedef fold< mpl::vector<int, long>, vector<>, push_back<mpl::_1, std::pair<int, mpl::_2> > >::type list_of_pairs;
Now, if we wrap this in a separate meta-function and output it for all types of the source list, we get:
typedef mpl::vector<int, long> typelist; template <typename T, typename Result> struct list_of_pairs : mpl::fold<typelist, Result, mpl::push_back<mpl::_1, std::pair<T, mpl::_2> > > {}; typedef mpl::fold< typelist, mpl::vector<>, mpl::lambda<list_of_pairs<mpl::_2, mpl::_1> > >::type result_type; BOOST_MPL_ASSERT( mpl::equal<result_type, mpl::vector4< std::pair<int, int>, std::pair<int,long>, std::pair<long,int>, std::pair<long,long> > >::value);
EDIT: answer to the second question:
Bringing a result containing only unique elements (in the sense that you spoke about) is a bit more active. First you need to define a meta function that compares two elements and returns mpl :: true_ / mpl :: false _:
template <typename P1, typename P2> struct pairs_are_equal : mpl::or_< mpl::and_< is_same<typename P1::first_type, typename P2::first_type>, is_same<typename P1::second_type, typename P2::second_type> >, mpl::and_< is_same<typename P1::first_type, typename P2::second_type>, is_same<typename P1::second_type, typename P2::first_type> > > {};
Then we need to define a meta function that tries to find the given element in this list:
template <typename List, typename T> struct list_doesnt_have_element : is_same< typename mpl::find_if<List, pairs_are_equal<mpl::_1, T> >::type, typename mpl::end<List>::type> {};
Now it can be used to create a new list so that no duplicates are inserted:
typedef mpl::fold< result_type, mpl::vector<>, mpl::if_< mpl::lambda<list_doesnt_have_element<mpl::_1, mpl::_2> >, mpl::push_back<mpl::_1, mpl::_2>, mpl::_1> >::type unique_result_type;
All this is from the top of the head, so you may need some kind of tuning here or there. But the idea must be right.
EDIT: minor fixes described by @rafak