Question

I'm trying to implement a compile-time hash algorithm using constexpr. I Downloaded Nov 2013 CTP because it has supported for constexpr but thats a lie...

#define hashCharacter(T, J)         (((T >> 0x0D) | (T << 0x13)) + J)

unsigned long constexpr GetHashCompile(const char * asSource, unsigned long asValue = 0)
{
return asSource[0] == '\0'
    ? asValue
    : GetHashCompile(asSource + 1, hashCharacter(asValue, asSource[0]));
} 

int main(int a, char ** b)
{
    const auto value = GetHashCompile("Hello from compiler");
    printf("%d", value);
}

GetHashCompile will not be generated at compile-time rather than runtime. How could i acomplish the above code using Visual Studio?. The same code works perfecly using GCC or CLANG.

Was it helpful?

Solution

Actually, the November 2013 CTP does not claim to fully support constexpr, but only claims to have a partial support for constexpr. The features list explicitely tells that constexpr is not supported for member functions and for arrays. Since string literals are a kind of array, they are not supported either:

The CTP supports C++11 constexpr, except for member functions. (Another limitation is that arrays aren't supported.) Also, it doesn't support C++14's extended constexpr rules.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top