constexpr将无法使用Visual C ++编译器2013年11月CTP(CTP_Nov2013) [英] constexpr won't work using Visual C++ Compiler Nov 2013 CTP (CTP_Nov2013)
问题描述
我试图使用constexpr实现编译时哈希算法。我下载了2013年11月CTP因为它支持constexpr,但是这是一个谎言...
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不会在编译时生成,我如何使用Visual Studio?上面的代码。相同的代码完全使用GCC或CLANG。
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.
推荐答案
实际上,2013年11月CTP没有声称完全支持 constexpr
,但只声称对 constexpr
有部分支持。 功能列表明确地告诉成员函数和数组不支持 constexpr
。由于字符串字面量是一种数组,它们不支持:
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:
CTP支持C ++ 11
constexpr
,除了成员函数。 (另一个限制是不支持数组。)另外,它不支持C ++ 14的扩展constexpr
规则。
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 extendedconstexpr
rules.
这篇关于constexpr将无法使用Visual C ++编译器2013年11月CTP(CTP_Nov2013)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!