繁体   English   中英

C++20 中的 constexpr std::vector 和 constexpr std::string

[英]constexpr std::vector and constexpr std::string in C++20

在新的 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}; 
}

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

为了使@Jovibor 的评论栩栩如生——如cppreference中所述,目前没有编译器支持constexpr std::vectorconstexpr std::string 你只需要稍等片刻。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM