C++ Constexpr字符串视图比较
我有一个在C++ Constexpr字符串视图比较,c++,constexpr,string-view,C++,Constexpr,String View,我有一个在GCC上编译的编译器,但没有在MSVC上编译哪个编译器不遵循constepr string\u视图比较的标准 #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 conste
GCC
上编译的编译器,但没有在MSVC
上编译哪个编译器不遵循constepr string\u视图
比较的标准
#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;
}
}
#包括
#包括
int main(int argc,字符**argv){
const constexpr auto a=“z”;
const constexpr std::字符串视图测试(“z”,1);
const constexpr std::string_view test2(a,1);
如果constexpr(test==test2){
返回5;
}
否则{
返回2;
}
}
C++17constepr if
语句
我们可以在错误消息中看到编译器资源管理器当前使用版本19.10.25017。您使用的是哪个版本的MSV?您会遇到什么错误?显然,它将只使用GCC 7.3进行编译,而不使用早期版本。我不熟悉MSVC版本控制,但从编译器资源管理器看,该版本似乎不支持
if constexpr
。页面详细介绍了C++17功能,并说“可以使用/std:C++17版本开关启用这些功能。”如果我在编译器资源管理器上添加该开关,它会告诉我这是一个未知选项。你试过用最新的MSVC在本地运行它吗?从if语句中删除constexpr并生成constexpr bool并不能修复它,但是@Bomaz在MSVS的字符串比较实现中似乎有一个bug。你应该报告它。@NathanOliver