Search code examples
c++g++generatorc++23

g++ "generator: No such file or directory" - which version of GCC supports the <generator> header?


I've built GCC 13.2.0 that I believe has quite good support for c++23.

I'm trying to compile some code that would use the c++23 std::generator.

For example: https://en.cppreference.com/w/cpp/coroutine/generator

c++23 should have the generator header: https://en.cppreference.com/w/cpp/coroutine/generator

#include <generator>

However when I compile this with g++ I get the following error:

$ ~/opt/gcc/13.2.0/bin/g++ -Wall -std=c++23 generator.cpp -o generator
generator.cpp:3:10: fatal error: generator: No such file or directory
    1 | #include <generator>
      |          ^~~~~~~~~~~
compilation terminated.

My guess is that 13.2.0 does not yet have support for this feature, but I'm struggling to confirm that guess. My question is, which version of GCC supports this feature?

I looked on this page: https://gcc.gnu.org/projects/cxx-status.html but nothing stood out that would tell me the answer.

Also I looked on this page: https://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html#status.iso.2023


Solution

  • Thanks to HolyBlackCat, I found the answer is GCC 14.

    At the time of writing this, 14 is not yet ready for release, but with a bit of poking around on gcc web site I found this page that seems to confirm it: https://gcc.gnu.org/gcc-14/changes.html

    Improved experimental support for C++23, including:

    ...

    The std::generator view for getting results from coroutines.

    ...