visual-studio - constexpr 无法使用 Visual C++ 编译器 2013 年 11 月 CTP (CTP_Nov2013)

标签 visual-studio c++11 constexpr

我正在尝试使用 constexpr 实现编译时哈希算法。我下载了 2013 年 11 月的 CTP,因为它支持 constexpr,但那是一个谎言...

#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 可以完美运行。

最佳答案

实际上,2013 年 11 月的 CTP 并没有声称完全支持 constexpr,而只是声称部分支持 constexprfeatures list明确告诉成员函数和数组不支持 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 extended constexpr rules.

关于visual-studio - constexpr 无法使用 Visual C++ 编译器 2013 年 11 月 CTP (CTP_Nov2013),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22546369/

相关文章:

c# - 在 ITextViewLine 上运行正则表达式(Visual Studio 扩展)

c++ - 在 C++11 中,如何实现适合内置类型层次结构的算术类型?

c++ - 寻找初始化为 const int 和 int 的指针的解释

c++ - std::add_const,为什么实现可以引用?

c++ - g++-7.0/访问硬件中 constexpr 函数的不同行为

c++ - 带有字符串操作解决方法的 constexpr?

c# - 如何在不重新编译的情况下在 .NET 中动态切换 Web 服务地址?

c# - 为什么在 Visual Studio 自动完成列表中有我的相同变量和 ':'?

visual-studio - Nuget 无法更新 .NET Core 项目

c++ - std::regex_replace 仅第一次出现