diff --git a/include/fmt/compile.h b/include/fmt/compile.h index 15158e3a..ec79d05e 100644 --- a/include/fmt/compile.h +++ b/include/fmt/compile.h @@ -185,14 +185,6 @@ class prepared_format { prepared_format() = delete; - template - inline OutputIt format_to(OutputIt out, const Args&... args) const { - typedef format_context_t context; - typedef output_range range; - format_arg_store as(args...); - return this->vformat_to(range(out), basic_format_args(as)); - } - typedef buffer_context context; template @@ -682,6 +674,17 @@ std::basic_string format(const CompiledFormat& cf, const Args&... args) { return to_string(buffer); } +template +OutputIt format_to(OutputIt out, const CompiledFormat& cf, + const Args&... args) { + using char_type = typename CompiledFormat::char_type; + using range = internal::output_range; + using context = format_context_t; + format_arg_store as(args...); + return cf.template vformat_to( + range(out), {make_format_args(args...)}); +} + template ::value)> format_to_n_result format_to_n(OutputIt out, unsigned n, diff --git a/include/fmt/format.h b/include/fmt/format.h index 7d274fac..8a78271d 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -3368,11 +3368,10 @@ inline OutputIt vformat_to(OutputIt out, const S& format_str, fmt::format_to(std::back_inserter(out), "{}", 42); \endrst */ -template +template ::value&& + internal::is_string::value)> inline OutputIt format_to(OutputIt out, const S& format_str, Args&&... args) { - static_assert(internal::is_output_iterator::value && - internal::is_string::value, - ""); internal::check_format_string(format_str); using context = format_context_t>; return vformat_to(out, to_string_view(format_str), diff --git a/include/fmt/safe-duration-cast.h b/include/fmt/safe-duration-cast.h index 61226e27..d0719512 100644 --- a/include/fmt/safe-duration-cast.h +++ b/include/fmt/safe-duration-cast.h @@ -257,16 +257,14 @@ To safe_duration_cast(std::chrono::duration from, // multiply with Factor::num without overflow or underflow if (Factor::num != 1) { - constexpr auto max1 = - std::numeric_limits::max() / - static_cast(Factor::num); + constexpr auto max1 = std::numeric_limits::max() / + static_cast(Factor::num); if (count > max1) { ec = 1; return {}; } - constexpr auto min1 = - std::numeric_limits::lowest() / - static_cast(Factor::num); + constexpr auto min1 = std::numeric_limits::lowest() / + static_cast(Factor::num); if (count < min1) { ec = 1; return {}; diff --git a/test/compile-test.cc b/test/compile-test.cc index 15331a69..6a546d79 100644 --- a/test/compile-test.cc +++ b/test/compile-test.cc @@ -643,32 +643,32 @@ TEST(PrepareTest, PassUserTypeFormat) { TEST(PrepareTest, FormatToArrayOfChars) { char buffer[32] = {0}; const auto prepared = fmt::compile("4{}"); - prepared.format_to(buffer, 2); + fmt::format_to(buffer, prepared, 2); EXPECT_EQ(std::string("42"), buffer); wchar_t wbuffer[32] = {0}; const auto wprepared = fmt::compile(L"4{}"); - wprepared.format_to(wbuffer, 2); + fmt::format_to(wbuffer, wprepared, 2); EXPECT_EQ(std::wstring(L"42"), wbuffer); } TEST(PrepareTest, FormatToIterator) { std::string s(2, ' '); const auto prepared = fmt::compile("4{}"); - prepared.format_to(s.begin(), 2); + fmt::format_to(s.begin(), prepared, 2); EXPECT_EQ("42", s); std::wstring ws(2, L' '); const auto wprepared = fmt::compile(L"4{}"); - wprepared.format_to(ws.begin(), 2); + fmt::format_to(ws.begin(), wprepared, 2); EXPECT_EQ(L"42", ws); } TEST(PrepareTest, FormatToBackInserter) { std::string s; const auto prepared = fmt::compile("4{}"); - prepared.format_to(std::back_inserter(s), 2); + fmt::format_to(std::back_inserter(s), prepared, 2); EXPECT_EQ("42", s); std::wstring ws; const auto wprepared = fmt::compile(L"4{}"); - wprepared.format_to(std::back_inserter(ws), 2); + fmt::format_to(std::back_inserter(ws), wprepared, 2); EXPECT_EQ(L"42", ws); }