mirror of
https://github.com/fmtlib/fmt.git
synced 2024-11-02 11:28:20 +00:00
Make ostream formatter work with compile-time format strings (#1692)
This commit is contained in:
parent
bd8804019b
commit
943532fece
@ -110,7 +110,8 @@ void format_value(buffer<Char>& buf, const T& value,
|
|||||||
template <typename T, typename Char>
|
template <typename T, typename Char>
|
||||||
struct fallback_formatter<T, Char, enable_if_t<is_streamable<T, Char>::value>>
|
struct fallback_formatter<T, Char, enable_if_t<is_streamable<T, Char>::value>>
|
||||||
: private formatter<basic_string_view<Char>, Char> {
|
: private formatter<basic_string_view<Char>, Char> {
|
||||||
auto parse(basic_format_parse_context<Char>& ctx) -> decltype(ctx.begin()) {
|
FMT_CONSTEXPR auto parse(basic_format_parse_context<Char>& ctx)
|
||||||
|
-> decltype(ctx.begin()) {
|
||||||
return formatter<basic_string_view<Char>, Char>::parse(ctx);
|
return formatter<basic_string_view<Char>, Char>::parse(ctx);
|
||||||
}
|
}
|
||||||
template <typename ParseCtx,
|
template <typename ParseCtx,
|
||||||
|
@ -302,3 +302,7 @@ std::ostream& operator<<(std::ostream& os, copyfmt_test) {
|
|||||||
TEST(OStreamTest, CopyFmt) {
|
TEST(OStreamTest, CopyFmt) {
|
||||||
EXPECT_EQ("foo", fmt::format("{}", copyfmt_test()));
|
EXPECT_EQ("foo", fmt::format("{}", copyfmt_test()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(OStreamTest, CompileTimeString) {
|
||||||
|
EXPECT_EQ("42", fmt::format(FMT_STRING("{}"), 42));
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user