T.L*_*T.L 6 c++ gcc gcc6 c++17
我正在尝试使用以下命令来编译包含使用gcc版本6.3.0的这段c ++ 17代码:std::sampleg++ -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可以正常编译)
我在这两页上找不到答案:
是的,从GCC 5开始,但直到GCC 7为止,它都在std::experimental命名空间中并在标头中定义<experimental/algorithm>。
来自 GCC 5 发行说明:
运行时库 (libstdc++)
改进了对 Library Fundamentals TS 的实验支持,包括:
- 函数模板 std::experimental::sample;
在 GCC 5.1 上测试https://wandbox.org/permlink/HWnX3qSgKbZO2qoH
| 归档时间: | 
 | 
| 查看次数: | 1940 次 | 
| 最近记录: |