mirror of
https://github.com/fmtlib/fmt.git
synced 2025-07-30 02:37:36 +02:00
Add support for incomplete types
This commit is contained in:
committed by
Victor Zverovich
parent
db405954cd
commit
c709138359
@ -2540,3 +2540,29 @@ TEST(base_test, format_byte) {
|
||||
EXPECT_EQ(s, "42");
|
||||
}
|
||||
#endif
|
||||
|
||||
// Only defined after the test case.
|
||||
struct incomplete_type;
|
||||
extern const incomplete_type& external_instance;
|
||||
|
||||
FMT_BEGIN_NAMESPACE
|
||||
template <> struct formatter<incomplete_type> : formatter<int> {
|
||||
auto format(const incomplete_type& x, context& ctx) const -> appender;
|
||||
};
|
||||
FMT_END_NAMESPACE
|
||||
|
||||
TEST(incomplete_type_test, format) {
|
||||
EXPECT_EQ(fmt::format("{}", external_instance), "42");
|
||||
}
|
||||
|
||||
struct incomplete_type {
|
||||
int i;
|
||||
};
|
||||
|
||||
const incomplete_type& external_instance = {42};
|
||||
|
||||
auto fmt::formatter<incomplete_type>::format(const incomplete_type& x,
|
||||
fmt::context& ctx) const
|
||||
-> fmt::appender {
|
||||
return formatter<int>::format(x.i, ctx);
|
||||
}
|
||||
|
Reference in New Issue
Block a user