fork download
  1. #include <boost/mpl/int.hpp>
  2. #include <boost/mpl/at.hpp>
  3. #include <boost/mpl/map.hpp>
  4.  
  5. namespace mpl = boost::mpl;
  6.  
  7. template<class T>
  8. struct size_traits{
  9. typedef typename boost::mpl::at<
  10. mpl::map<
  11. mpl::pair<mpl::int_<sizeof(bool)>, bool>,
  12. mpl::pair<mpl::int_<sizeof(char)>, char>,
  13. mpl::pair<mpl::int_<sizeof(short)>, short>,
  14. mpl::pair<mpl::int_<sizeof(int)>, int>,
  15. mpl::pair<mpl::int_<sizeof(long)>, long>,
  16. mpl::pair<mpl::int_<sizeof(long long)>, long long>,
  17. mpl::pair<mpl::int_<sizeof(float)>, float>,
  18. mpl::pair<mpl::int_<sizeof(double)>, double>
  19. >,
  20. mpl::int_<sizeof(T)>
  21. >::type type;
  22. };
  23.  
  24. #include <iostream>
  25. #include <typeinfo>
  26.  
  27. int main(){
  28. std::cout
  29. << typeid(size_traits<bool>::type ).name() << "\n"
  30. << typeid(size_traits<char>::type ).name() << "\n"
  31. << typeid(size_traits<short>::type ).name() << "\n"
  32. << typeid(size_traits<int>::type ).name() << "\n"
  33. << typeid(size_traits<long>::type ).name() << "\n"
  34. << typeid(size_traits<long long>::type).name() << "\n"
  35. << typeid(size_traits<float>::type ).name() << "\n"
  36. << typeid(size_traits<double>::type ).name() << "\n"
  37. << typeid(size_traits<void*>::type ).name() << "\n";
  38. return 0;
  39. }
Success #stdin #stdout 0.02s 2724KB
stdin
Standard input is empty
stdout
c
c
s
f
f
d
f
d
f