I have a constexpr function that computes CRC32 hash from string literal.
template <size_t len>
constexpr uint32_t ctcrc32(const char (&str)[len]) {
return detail::crc32<len - 2>(str) ^ 0xFFFFFFFF;
}
(it refers to other constexpr functions)
What I want to do is to call some other function that accepts uint32_t value and uses it to access data in some unordered_map. Such call looks like this:
uniformByNameCRC32(ctcrc32("uPointLight.position"));
I expect that "uPointLight.position"'s hash computes once at build time and then a resulting constant is passed to uniformByNameCRC32(), but that is not the case and ctcrc32() is called at runtime which kills CPU basically, since I have a lot of uniformByNameCRC32() calls.
This, however, works fine:
std::array<uint64_t, ctcrc32("string_literal")> array;
Such code compiles and indicates that ctcrc32()'s return value is indeed a constexpr.
What am I missing here?
Aucun commentaire:
Enregistrer un commentaire