簡體   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