From 16637341b9d9871ca406fcd484ef8e07d66016da Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Fri, 12 Jun 2020 13:24:49 -0700 Subject: [PATCH] Enable compilation for all types --- include/fmt/compile.h | 10 +++------- test/compile-test.cc | 7 +++++++ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/include/fmt/compile.h b/include/fmt/compile.h index d486a867..0c37adc4 100644 --- a/include/fmt/compile.h +++ b/include/fmt/compile.h @@ -468,12 +468,8 @@ constexpr auto compile_format_string(S format_str) { return parse_tail(make_text(str, POS, 1), format_str); } else if constexpr (str[POS + 1] == '}') { using type = get_type; - if constexpr (std::is_same::value) { - return parse_tail(field(), - format_str); - } else { - return unknown_format(); - } + return parse_tail(field(), + format_str); } else { return unknown_format(); } @@ -565,7 +561,7 @@ FMT_INLINE std::basic_string format(S, Args&&... args) { if (str.size() == 2 && str[0] == '{' && str[1] == '}') return fmt::to_string(detail::first(args...)); constexpr auto compiled = compile(S()); - return format(compiled, std::forward(args...)); + return format(compiled, std::forward(args)...); } template (""); EXPECT_EQ(fmt::format(f), ""); } + +#ifdef __cpp_if_constexpr +TEST(CompileTest, Basic) { + EXPECT_EQ("42", fmt::format(FMT_COMPILE("{}"), 42)); + EXPECT_EQ("foo", fmt::format(FMT_COMPILE("{}"), "foo")); +} +#endif