admin管理员组文章数量:1315783
Take a look at this snippet:
// test.cpp
#include <print>
#include <vector>
int main () {
std::vector<int> vec = {1,2,3};
std::println("vector: {}",vec);
return 0;
}
From here I understood that the C++23 feature "support for the formatted output library " (P2093R14) had been added in GCC 14, Clang 18 and MSVC 19.37.
Compiled with MSVC 19.42 the program yields the desired ouput:
cl /EHs test.cpp /std:c++latest
D:\>test.exe vector: [1, 2, 3]
But with GCC 14 and Clang 19 it does not compile.
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>> && ...)
Am I missing something?
Take a look at this snippet:
// test.cpp
#include <print>
#include <vector>
int main () {
std::vector<int> vec = {1,2,3};
std::println("vector: {}",vec);
return 0;
}
From here I understood that the C++23 feature "support for the formatted output library " (P2093R14) had been added in GCC 14, Clang 18 and MSVC 19.37.
Compiled with MSVC 19.42 the program yields the desired ouput:
cl /EHs test.cpp /std:c++latest
D:\>test.exe vector: [1, 2, 3]
But with GCC 14 and Clang 19 it does not compile.
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>> && ...)
Am I missing something?
Share Improve this question asked Jan 30 at 13:34 Angle.BracketAngle.Bracket 1,5321 gold badge15 silver badges36 bronze badges 4 |1 Answer
Reset to default 9Formatter for std::vector
is a part of P2286R8 "Formatting Ranges" and is not yet supported by libstdc++. (Both GCC and Clang use libstdc++ as the default standard library implementation on Linux.)
本文标签: cWhy does stdprintln with STL containers not compile with GCC and ClangStack Overflow
版权声明:本文标题:c++ - Why does std::println with STL containers not compile with GCC and Clang? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741962163a2407341.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
<plenty of more lines to follow>
- those lines are noisy but provide information. Please don't delete them. Use a quoted-code-block or something. – Yakk - Adam Nevraumont Commented Jan 30 at 15:03Formatting Ranges (FTM)*
godbolt./z/Ezrj3EPs5 – Marek R Commented Jan 30 at 15:49apt -qq list libstdc++-14-dev
sayslibstdc++-14-dev/noble-updates,noble-security,now 14.2.0-4ubuntu2~24.04 amd64 [installed]
– Angle.Bracket Commented Jan 30 at 15:57