skypjack / entt

Gaming meets modern C++ - a fast and reliable entity component system (ECS) and much more
https://github.com/skypjack/entt/wiki
MIT License
10.15k stars 889 forks source link

512 constexpr recursive template limit on clang for big templates (id generation) #400

Closed Milerius closed 4 years ago

Milerius commented 4 years ago

AS discussed on gitter i open the issue here:

/home/milerius/vcpkg/installed/x64-linux/include/entt/entity/../core/hashed_string.hpp:72:41: note: constexpr evaluation exceeded maximum depth of 512 calls

/home/milerius/vcpkg/installed/x64-linux/include/entt/entity/../core/type_info.hpp:60:24: fatal error: constexpr variable 'value' must be initialized by a constant expression constexpr auto value = entt::hashed_string::value(ENTT_PRETTY_FUNCTION_CONSTEXPR)

indianakernick commented 4 years ago

I used djb2 for the same purpose long ago.

size_t djb2(const char *str) {
  size_t hash = 5381;
  while (char c = *str++) {
    hash = ((hash << 5) + hash) ^ c;
  }
  return hash;
}
skypjack commented 4 years ago

I think we can easily make fnv not recursive. I'll try it before to use a different algorithm. Nice to know that djb2 fits the purpose btw. Thanks for pointing this out. :+1: