【问题标题】:constexpr std::vector and constexpr std::string in C++20C++20 中的 constexpr std::vector 和 constexpr std::string
【发布时间】:2020-12-03 08:59:49
【问题描述】:

在新的 c++20 中,std::vector 和 std::string 具有 constexpr 构造函数(和其他方法)。我学习了https://www.heise.de/developer/artikel/constexpr-std-vector-und-constexpr-std-string-in-C-20-4906108.html 文章,其中包含使用向量和字符串的 constexpr 版本的示例。但是,当我尝试使用不同的编译器(最新版本)在 https://godbolt.org 上测试这段代码时,它们都完全失败了。

例如这段代码(带有 -std=c++20 键)

int main()
{
    constexpr std::vector myVec {15, -5, 0, 5, 10}; 
}

这个功能还不支持吗? ...或者..如何使用这个?

【问题讨论】:

标签: c++ stdvector constexpr c++20 stdstring


【解决方案1】:

要使@Jovibor's comment 栩栩如生 - 如cppreference 中所述,目前没有编译器支持constexpr std::vectorconstexpr std::string。您只需稍等片刻即可。

【讨论】:

    猜你喜欢
    • 2020-12-22
    • 1970-01-01
    • 2021-09-06
    • 1970-01-01
    • 1970-01-01
    • 2021-11-19
    • 2019-12-27
    • 1970-01-01
    • 2011-08-02
    相关资源
    最近更新 更多