fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <typeinfo>
  5. #include <boost/mpl/list.hpp>
  6. #include <boost/mpl/map.hpp>
  7. #include <boost/mpl/for_each.hpp>
  8. #include <boost/mpl/key_type.hpp>
  9.  
  10. using namespace boost;
  11. using namespace std;
  12.  
  13. struct Disp {
  14. template <class Type>
  15. void operator()(const Type&) const
  16. {
  17. cout << typeid(Type).name() << endl;
  18. }
  19. template <typename K, typename V>
  20. void operator()(const mpl::pair<K,V>&) const {
  21. cout << typeid(K).name() << "," << typeid(V).name() << endl;
  22. }
  23. } disp;
  24.  
  25.  
  26. int main()
  27. {
  28. typedef mpl::list<int, std::string, char, std::vector<int> > tl;
  29. typedef mpl::map<mpl::pair<int,char>, mpl::pair<int,int>, mpl::pair<char, char> > t2;
  30.  
  31. cout << "mpl list test" << endl;
  32. mpl::for_each<tl>(disp);
  33. cout << "mpl map test" << endl;
  34. mpl::for_each<t2>(disp);
  35. cout << "mpl map key_type test" << endl;
  36. mpl::for_each<t2, mpl::lambda<mpl::key_type<t2, mpl::_1> > >(disp);
  37. cout << "finish" << endl;
  38.  
  39. return 0;
  40. }
  41.  
Success #stdin #stdout 0.02s 2684KB
stdin
Standard input is empty
stdout
mpl list test
i
Ss
c
St6vectorIiSaIiEE
mpl  map test
i,c
i,i
c,c
mpl  map key_type test
i
i
c
finish