Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

gcc

c++17

gcc6

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++ compiler support
  • C++ Standards Support in GCC
like image 247
T.L Avatar asked Sep 10 '18 22:09

T.L


People also ask

Does my GCC support C ++ 17?

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.

Is C ++ 17 supported?

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.

What version of C++ does GCC support?

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.

Does GCC 11 support C ++ 14?

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.


1 Answers

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

like image 152
Nikita Kniazev Avatar answered Sep 22 '22 08:09

Nikita Kniazev