gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:41:47 26 4
gpt4 key购买 nike

我正在尝试编译这段包含 std::samplec++ 17 代码使用 gcc 版本 6.3.0 和以下命令:g++ -std=gnu++17 -c main.cpp

但我得到这个:错误:‘sample’不是‘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 下编译良好)

我在这两页上找不到答案:

最佳答案

是的,因为 GCC 5 , 但直到 GCC 7它在 std::experimental命名空间并在 <experimental/algorithm> 中定义标题。

来自 GCC 5 发行说明:

Runtime Library (libstdc++)

  • Improved experimental support for the Library Fundamentals TS, including:

    • function template std::experimental::sample;

在 GCC 5.1 上测试 https://wandbox.org/permlink/HWnX3qSgKbZO2qoH

关于c++ - gcc 6 是否支持使用 std::sample (c++17)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52266354/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com