【发布时间】: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};
}
这个功能还不支持吗? ...或者..如何使用这个?
【问题讨论】:
-
en.cppreference.com/w/cpp/compiler_support big 3 还不支持它们。
标签: c++ stdvector constexpr c++20 stdstring