3 ms·
Much less so with functions at compile time. The first thing I noticed was his example of the fibonacci numbers at compile-time. You can do those things with re
by fwsgonzo 6y ago
Much less so with functions at compile time. The first thing I noticed was his example of the fibonacci numbers at compile-time. You can do those things with regular functions now, and just marking it as constexpr or constinit.
I actually took the CRC32 algorithm and just slapped a template <int polynomial> and a constexpr on it, and called it CRC32 at compile-time. I'm using it for tons of string-hashing stuff where I want to replace a string with just a 32-bit number. It's incredibly efficient.
- layoutIfNeeded 6y agoHow does that look like in practice? I mean, you can’t use the table-based per-byte approach because you can’t store the lookup table with constexpr, so I guess you must be doing polynomial division via bit shifts and such, right?
- TeMPOraL 6y ago> you can’t store the lookup table with constexpr IIRC you can store a null-terminated string as constexpr, right? If so, then there's your lookup table.
- Google234 6y agoAlso I think absl has a constexpr map too.
- layoutIfNeeded 6y agoBut string literals are const, so you won’t be able to fill the lookup table based on the generator polynomial.
- fwsgonzo 6y agoThere is a table, here is the code: https://github.com/fwsGonzo/rvscript/blob/master/engine/script/util/crc32.hpp https://github.com/fwsGonzo/rvscript/blob/master/engine/scri...
- layoutIfNeeded 6y agoAh, true! I wasn’t aware that std::array was compatible with constexpr.
- sgerenser 6y agoI’ve done compile time crc32 string hashing for similar reasons with a raw array as a lookup table.