Make ostream formatter work with compile-time format strings (#1692)

This commit is contained in:
Victor Zverovich 2020-05-20 14:59:57 -07:00
parent bd8804019b
commit 943532fece
2 changed files with 6 additions and 1 deletions

View File

@ -110,7 +110,8 @@ void format_value(buffer<Char>& buf, const T& value,
template <typename T, typename Char>
struct fallback_formatter<T, Char, enable_if_t<is_streamable<T, Char>::value>>
: 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);
}
template <typename ParseCtx,

View File

@ -302,3 +302,7 @@ std::ostream& operator<<(std::ostream& os, copyfmt_test) {
TEST(OStreamTest, CopyFmt) {
EXPECT_EQ("foo", fmt::format("{}", copyfmt_test()));
}
TEST(OStreamTest, CompileTimeString) {
EXPECT_EQ("42", fmt::format(FMT_STRING("{}"), 42));
}