查看此片段:
// test.cpp
#include <print>
#include <vector>
int main () {
std::vector<int> vec = {1,2,3};
std::println("vector: {}",vec);
return 0;
}
从Herey我了解C ++ 23功能“对格式的输出库的支持”(P2093R14)已在GCC 14,Clang 18和MSVC 19.37中添加。 与MSVC结合19.42该程序产生所需的OUPUT:
cl /EHs test.cpp /std:c++latest
D:\>test.exe vector: [1, 2, 3]
,但使用GCC 14和Clang 19,它没有编译。
clang++ test.cpp -std=c++23
/usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/format:4065:3: error:
static assertion failed due to requirement
'is_default_constructible_v<std::formatter<std::vector<int, std::allocator<int>>,
char>>': <plenty of more lines to follow>
g++ test.cpp -std=c++23
/usr/include/c++/14/format:4065:10: error: static assertion failed:
std::formatter must be specialized for each type being formatted
(is_default_constructible_v<formatter<_Args, _CharT>> && ...)
我错过了什么?
formatters的