fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3. namespace detail
  4. {
  5. template<size_t Count>
  6. inline constexpr size_t countof(const char(&string)[Count])
  7. {
  8. return Count - 1;
  9. }
  10.  
  11. template<typename T>
  12. struct ascii_hash_t
  13. {
  14. template<typename L>
  15. static constexpr T f(L const& data, T hash, size_t i = 0)
  16. {
  17. return i < countof(data) ? f(data, (hash & (~0u)) ^ (hash << 7) ^ T(data[i]), i + 1) : hash;
  18. }
  19. };
  20.  
  21. template<typename T, typename L>
  22. inline constexpr T generate_ascii_hash(L const& data)
  23. {
  24. return detail::ascii_hash_t<T>::f(data, 0);
  25. }
  26. };
  27.  
  28. template<size_t Count>
  29. inline constexpr uint32_t hash_constexpr(const char(&string)[Count])
  30. {
  31. return detail::generate_ascii_hash<uint32_t>(string);
  32. }
  33. int main() {
  34. // your code goes here
  35. constexpr uint32_t asd = hash_constexpr("asdasd");
  36. return 0;
  37. }
Success #stdin #stdout 0s 3336KB
stdin
Standard input is empty
stdout
Standard output is empty