Search code examples
c++gccstdfmtc++23

Does GCC support C++23 std::print?


On CppCon 2022 was announced, that new official HelloWorld in C++ is now:

#include <print>

int main() {
 std::print("Hello world\n");
 return 0;
}

Do you know, is std::print available in GCC ? Maybe it needs some flag or additional library to activate?

Link to description https://en.cppreference.com/w/cpp/io/print


Solution

  • The status of C++ features is tracked via their feature test macros. cppreference.com helpfully lists those. They would be __cpp_lib_print and __cpp_lib_format for print and format, respectively.

    You can then search for those macros in the C++ Standards Support in GCC and Implementation Status of libstdc++. Right now you will find no mention of __cpp_lib_print while __cpp_lib_format is listed but not implemented. So the answer is no.

    You can check your own compiler with the feature testing facilities of C++. An online compiler like godbolt.org is a quick way to test most mainstream ones.


    UPDATE:

    std::print and std::format support had been added to GCC since version 14.

    To check, just invoke

    $ g++ --version
    

    see the output and -in case- update the compiler.