c++ - constexpr string_view 比较

标签 c++ constexpr string-view

我有a small programGCC 上编译,但在 MSVC 上编译,哪个编译器不遵循 constexpr string_view 比较标准?

#include <iostream>
#include <string_view>

int main(int argc, char **argv) {
    const constexpr auto a = "z";
    const constexpr std::string_view test("z",1);
    const constexpr std::string_view test2(a,1);
    if constexpr(test == test2) {
        return 5;
    }
    else{
        return 2;
    }
}

最佳答案

C++17 constexpr if 语句 are supported since MSVC 19.11 .

在报错信息中我们可以看到,Compiler Explorer目前使用的是19.10.25017版本。

关于c++ - constexpr string_view 比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49776429/

相关文章:

c++ - static constexpr 函数与全局函数不同?

c++ - 创建一个编译时字符串重复一个字符 n 次

c++ - 在这种情况下使用 string_view 会导致不必要的字符串复制吗?

c++ - 如何将 Visual Studio 2005 的平台工具集添加到较新 IDE 版本的 `Platform Toolset` 列表中?

c++ - 如何在 C++ 中动态分配连续的二维数组?

c++ - IMFSourceReader M4A 音频精确帧搜索

C++使用字符串调用对象成员函数

c++ - 评估不同参数的 constexpr 函数时的运行时差异

c++ - virtual constexpr 函数如何实现?

c++ - 为什么 std::string_view::data 不包含空终止符?