fork(1) download
  1. #include <iostream>
  2.  
  3. template<std::uintmax_t, char...>
  4. struct parse_impl;
  5.  
  6. template<std::uintmax_t Rest>
  7. struct parse_impl<Rest>
  8. {
  9. static constexpr std::uintmax_t value = Rest / 10;
  10. };
  11.  
  12. template<std::uintmax_t Rest, char Head, char... Tail>
  13. struct parse_impl<Rest, Head, Tail...>
  14. {
  15. static constexpr std::uintmax_t value = parse_impl<(Rest + (Head - '0')) * 10, Tail...>::value;
  16. };
  17.  
  18. template<char... Number>
  19. struct parse
  20. {
  21. static constexpr std::uintmax_t value = parse_impl<0, Number...>::value;
  22. };
  23.  
  24. int main()
  25. {
  26. std::cout << parse<'1', '2', '3'>::value << '\n';
  27. std::cout << parse<'4', '7', '9', '2', '5'>::value;
  28. return 0;
  29. }
  30.  
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
123
47925