It seems that gcc has some limitation on complex constant folding. Here is an example:
static inline unsigned int DJBHash(const char *str)
{
int i;
uns
Perhaps C++ TMP might be able to do it. I'm not sure though.
It is possible if you don't mind using variadic character literal lists instead of string literals:
#include
#include
template
struct DJBhash_helper
: std::integral_constant {};
template
struct DJBhash_helper
: DJBhash_helper<(acc << 5) + acc + head, tail...> {};
template
struct DJBhash
: DJBhash_helper<5381, str...> {};
int main()
{
std::cout << DJBhash<'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'0', '1', '2', '3', '4', '5', '6', '7'>::value << '\n';
}
ideone live demo