GCC 是否支持 C++20 std::format?

Does GCC support C++20 std::format?

如果没有,您知道什么编译器或版本会吗?

cppreference/format

Does gcc support C++20 std::format?

还没有!

还没有编译器支持,甚至 gcc 11 也不支持。请参阅库功能中的 Text formatting

Compiler support for C++20 library features

截至今天(2022 年 4 月 13 日),GCC 11.2 不支持此功能。或者更确切地说,它的标准库实现不支持它(因为它是一个库功能,而不是编译器功能)。

您现在可以尝试 Clang 14.0.0 及更高版本,但请注意以下几点:

libc++ of Clang 14.0.0 has std::format support but: "The paper is implemented but still marked as an incomplete feature. Not yet implemented LWG-issues will cause API and ABI breakage" as mentioned here

您也可以尝试 MSVC 16.10 及更高版本。提到 std::format 的支持已完成。


标准库的当前状态可以在这里看到:

截至 2022 年 5 月,GCC 11.2 不支持 std::format 还没有。

MSVC(版本16.10及以上)是唯一完全支持std::format[=的编译器41=]。 Clang 14(带有 libc++14)也几乎完全支持 std::format.

因为 std::format 是基于 fmt 库,你可以使用 fmt::format 直到 std::format 到达 GCC。

{fmt} library GitHub repo


在此处查看编译器支持:-