Combination of types using boost::mpl

I have a list of types, from which I want to construct the list of all combinations with two elements. For example:

namespace mpl = boost::mpl;
typedef mpl::vector<int, long> typelist;
// mpl magic...
// the wanted list is equivalent to:
typedef mpl::vector<pair<int, int>, pair<int, long>,
                    pair<long, int>, pair<long, long> > combinations;

Here, pair<T1,T2> could be std::pair<T1,T2>, or mpl::vector<T1,T2>. How to do this? I would also be interested in removing the duplicates when we consider that pair<T1, T2> == pair<T2, T1>.
Thanks.



Bookmark and Share   Read more Read more...   Source: Stack Overflow