【问题标题】:Constexpr string_view comparisonconstexpr string_view 比较
【发布时间】: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 constexprThis 页面详细介绍了 C++17 功能,并说“可以使用 /std:c++17 版本开关启用这些功能。”如果我在 Compiler Explorer 上添加该开关,它会告诉我这是一个未知选项。您是否尝试过使用最新的 MSVC 在本地运行它?

标签: c++ constexpr string-view


【解决方案1】:

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

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

【讨论】:

猜你喜欢
  • 2023-03-18
  • 1970-01-01
  • 1970-01-01
  • 2021-06-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-08-27
  • 1970-01-01
相关资源
最近更新 更多