fork download
  1. #include <iostream>
  2.  
  3. #include <boost/mpl/pair.hpp>
  4. #include <boost/mpl/vector.hpp>
  5. #include <boost/mpl/sort.hpp>
  6. #include <boost/mpl/for_each.hpp>
  7.  
  8. using namespace boost;
  9.  
  10. template <int V, int P>
  11. using Value = mpl::pair<mpl::int_<V>, mpl::int_<P> >;
  12.  
  13. typedef mpl::vector<Value<3, 12>, Value<5, 1>, Value<0, 16> >::type RawData;
  14. typedef mpl::sort<RawData, mpl::less<mpl::first<mpl::_1>, mpl::first<mpl::_2> > >::type SortedData;
  15.  
  16. struct Printer {
  17. template<typename T> void operator()(T) {
  18. std::cout << mpl::first<T>::type::value << ": " << mpl::second<T>::type::value << std::endl;
  19. }
  20. };
  21.  
  22. int main() {
  23. std::cout << "Raw: " << std::endl;
  24. mpl::for_each<RawData>(Printer());
  25. std::cout << "Sorted: " << std::endl;
  26. mpl::for_each<SortedData>(Printer());
  27. return 0;
  28. }
Success #stdin #stdout 0s 16048KB
stdin
Standard input is empty
stdout
Raw: 
3: 12
5: 1
0: 16
Sorted: 
0: 16
3: 12
5: 1