【发布时间】:2018-04-11 13:28:13
【问题描述】:
我有a small program 可以在GCC 上编译,但不能在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;
}
}
【问题讨论】:
-
您使用的是哪个版本的 MSVS?你得到什么错误?
-
显然它只能与 GCC 7.3 一起编译,而不能与早期版本一起编译。
-
我不熟悉 MSVC 版本控制,但从 Compiler Explorer 看来该版本不支持
if constexpr。 This 页面详细介绍了 C++17 功能,并说“可以使用 /std:c++17 版本开关启用这些功能。”如果我在 Compiler Explorer 上添加该开关,它会告诉我这是一个未知选项。您是否尝试过使用最新的 MSVC 在本地运行它?
标签: c++ constexpr string-view