fork download
  1. #include <type_traits>
  2. #include <iostream>
  3.  
  4. template<unsigned acc, char... values>
  5. struct DJBhash_helper
  6. : std::integral_constant<unsigned, acc> {};
  7.  
  8. template<unsigned acc, char head, char... tail>
  9. struct DJBhash_helper<acc, head, tail...>
  10. : DJBhash_helper<(acc << 5) + acc + head, tail...> {};
  11.  
  12. template<char... str>
  13. struct DJBhash
  14. : DJBhash_helper<5381, str...> {};
  15.  
  16. int main()
  17. {
  18. std::cout << DJBhash<'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
  19. '0', '1', '2', '3', '4', '5', '6', '7'>::value << '\n';
  20. }
  21.  
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
3434365166