mirror of
https://github.com/fmtlib/fmt.git
synced 2026-07-30 16:26:27 +08:00
This commit is contained in:
parent
1a99c2630c
commit
af2d9f2b78
@ -178,6 +178,10 @@ template <typename Char, typename V, int N> struct field {
|
||||
if constexpr (std::is_convertible<V, basic_string_view<Char>>::value) {
|
||||
auto s = basic_string_view<Char>(arg);
|
||||
return copy<Char>(s.begin(), s.end(), out);
|
||||
} else if constexpr (use_format_as<V>::value) {
|
||||
return write<Char>(out, format_as(arg));
|
||||
} else if constexpr (use_format_as_member<V>::value) {
|
||||
return write<Char>(out, formatter<V>::format_as(arg));
|
||||
} else {
|
||||
return write<Char>(out, arg);
|
||||
}
|
||||
|
||||
@ -479,3 +479,13 @@ TEST(compile_test, constexpr_string_format) {
|
||||
EXPECT_TRUE(big);
|
||||
}
|
||||
#endif // FMT_USE_CONSTEXPR_STRING
|
||||
|
||||
namespace {
|
||||
struct compile_format_as_type {
|
||||
int value;
|
||||
};
|
||||
int format_as(compile_format_as_type f) { return f.value; }
|
||||
}
|
||||
TEST(compile_test, format_as) {
|
||||
EXPECT_EQ("42", fmt::format(FMT_COMPILE("{}"), compile_format_as_type{42}));
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user