constexpr won't work using Visual C++ Compiler Nov 2013 CTP (CTP_Nov2013)

喜欢而已 提交于 2019-12-10 23:51:51

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/22546369/constexpr-wont-work-using-visual-c-compiler-nov-2013-ctp-ctp-nov2013

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!