簡體   English   中英

gcc 6是否支持使用std :: sample(c ++ 17)?

[英]Does gcc 6 support the use of std::sample (c++17)?

我正在嘗試使用gcc版本6.3.0使用以下命令編譯包含std::sample這段c ++ 17代碼: g++ -std=gnu++17 -c main.cpp

但是我得到了這個: error: 'sample' is not a member of 'std' ......

#include <vector>
#include <algorithm>
#include <random>

int main()
{
    std::vector<int> a{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    std::vector<int> b(5);

    std::sample(a.begin(), a.end(), 
                b.begin(), b.size(),
                std::mt19937{std::random_device{}()});

    return 0;
}

gcc 6是否支持使用std::sample (用gcc 8.2.0編譯好)

我在這兩頁上找不到答案:

我們可以從“庫基礎V1 TS組件:采樣”下的文檔中表中看到,支持std::sample的最早版本的libstdc ++是版本7.1

gcc 6是否支持使用std :: sample?

不。您需要GCC 7.從GCC 7發行說明

  • 對C ++ 17的實驗支持,包括以下新功能:

    • ...

    • std :: sample,std :: default_searcher,std :: boyer_moore_searcher和std :: boyer_moore_horspool_searcher;

對於GCC 7,您可能需要-std=c++1z-std=gnu++1z因為它是實驗性的。

是的,從GCC 5開始 ,但是直到GCC 7,它在std::experimental命名空間中並在<experimental/algorithm>標頭中定義。

來自GCC 5發行說明:

運行時庫(libstdc ++)

  • 改進了對圖書館基礎知識TS的實驗支持,包括:

    • 函數模板std :: experimental :: sample;

在GCC 5.1上測試https://wandbox.org/permlink/HWnX3qSgKbZO2qoH

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM