I'm trying to compile this piece of c++ 17 code that contains std::sample
using gcc version 6.3.0 with the following command: g++ -std=gnu++17 -c main.cpp
.
But I get this: 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;
}
Does gcc 6 support the use of std::sample
? (It compiles fine with gcc 8.2.0)
I could not find the answer on this two pages:
C++17 features are available since GCC 5. This mode is the default in GCC 11; it can be explicitly selected with the -std=c++17 command-line flag, or -std=gnu++17 to enable GNU extensions as well.
Compiler supportGCC has had complete support for C++17 language features since version 8. Clang 5 and later supports all C++17 language features. Visual Studio 2017 15.8 (MSVC 19.15) and later supports all C++17 language features.
Master C and Embedded C Programming- Learn as you goC++98 − GCC has full support for the 1998 C++ standard as modified in 2003 and renamed to C++03 and some later defect reports. C++11 − GCC 4.8. 1 was the first complete implementation of the 2011 C++ standard, previously known as C++0x.
According to cppreference, full support of c++11 came with gcc 4.8. 1; To have full support of c++14 (with some of the new features of c++17), instead, you need gcc 5.0 and above.
Yes, since GCC 5, but until GCC 7 it is in std::experimental
namespace and defined in <experimental/algorithm>
header.
From GCC 5 Release notes:
Runtime Library (libstdc++)
Improved experimental support for the Library Fundamentals TS, including:
- function template std::experimental::sample;
Tested on GCC 5.1 https://wandbox.org/permlink/HWnX3qSgKbZO2qoH
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With