fork(3) download
  1. #include <type_traits>
  2. #include <iostream>
  3.  
  4.  
  5. template<size_t i>
  6. struct best_type {
  7. typedef typename std::conditional<
  8. (i <= 8),
  9. uint8_t,
  10. typename std::conditional<
  11. (i <= 16),
  12. uint16_t,
  13. typename std::conditional<
  14. (i <= 32),
  15. uint32_t,
  16. uint64_t
  17. >::type
  18. >::type
  19. >::type type;
  20. };
  21.  
  22.  
  23. int main() {
  24. std::cout << sizeof(best_type<2>::type) << std::endl;
  25. std::cout << sizeof(best_type<8>::type) << std::endl;
  26. std::cout << sizeof(best_type<15>::type) << std::endl;
  27. std::cout << sizeof(best_type<17>::type) << std::endl;
  28. }
Success #stdin #stdout 0s 2884KB
stdin
Standard input is empty
stdout
1
1
2
4