From 61e6d2e38cd967e1c0e7aef8936c3581c56f03a6 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Wed, 24 Oct 2018 18:42:42 -0700 Subject: [PATCH] Fix core version of vformat_to --- include/fmt/core.h | 15 +++++++-------- include/fmt/format.h | 15 +++++++++++---- src/format.cc | 3 +++ test/core-test.cc | 10 ++++++++++ 4 files changed, 31 insertions(+), 12 deletions(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index 8180340b..ecd145ee 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -16,7 +16,7 @@ #include // The fmt library version in the form major * 10000 + minor * 100 + patch. -#define FMT_VERSION 50201 +#define FMT_VERSION 50202 #ifdef __has_feature # define FMT_HAS_FEATURE(x) __has_feature(x) @@ -1350,6 +1350,11 @@ template std::basic_string vformat( basic_string_view format_str, basic_format_args::type> args); + +template +typename buffer_context::type::iterator vformat_to( + internal::basic_buffer &buf, basic_string_view format_str, + basic_format_args::type> args); } /** @@ -1371,16 +1376,10 @@ inline internal::named_arg arg(wstring_view name, const T &arg) { return {name, arg}; } -// This function template is deleted intentionally to disable nested named -// arguments as in ``format("{}", arg("a", arg("b", 42)))``. +// Disable nested named arguments, e.g. ``arg("a", arg("b", 42))``. template void arg(S, internal::named_arg) = delete; -template -typename buffer_context::type::iterator vformat_to( - internal::basic_buffer &buf, const S &format_str, - basic_format_args > args); - template struct is_contiguous: std::false_type {}; diff --git a/include/fmt/format.h b/include/fmt/format.h index bbe4926c..f3302597 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -3365,15 +3365,22 @@ std::basic_string to_string(const basic_memory_buffer &buf) { return std::basic_string(buf.data(), buf.size()); } -template -inline typename buffer_context::type::iterator vformat_to( - internal::basic_buffer &buf, const String &format_str, +template +typename buffer_context::type::iterator internal::vformat_to( + internal::basic_buffer &buf, basic_string_view format_str, basic_format_args::type> args) { - typedef back_insert_range > range; + typedef back_insert_range > range; return vformat_to>( buf, to_string_view(format_str), args); } +template +inline typename buffer_context::type::iterator vformat_to( + internal::basic_buffer &buf, const S &format_str, + basic_format_args::type> args) { + return vformat_to(buf, to_string_view(format_str), args); +} + template < typename S, typename... Args, std::size_t SIZE = inline_buffer_size, diff --git a/src/format.cc b/src/format.cc index cd291294..8f7a5991 100644 --- a/src/format.cc +++ b/src/format.cc @@ -28,6 +28,9 @@ template FMT_API int internal::char_traits::format_float( template FMT_API std::string internal::vformat( string_view, basic_format_args); +template format_context::iterator internal::vformat_to( + internal::buffer &, string_view, basic_format_args); + template FMT_API void internal::sprintf_format( double, internal::buffer &, core_format_specs); template FMT_API void internal::sprintf_format( diff --git a/test/core-test.cc b/test/core-test.cc index 77d35428..02fe7267 100644 --- a/test/core-test.cc +++ b/test/core-test.cc @@ -532,6 +532,16 @@ TEST(CoreTest, Format) { EXPECT_EQ(fmt::format("{}", 42), "42"); } +TEST(CoreTest, FormatTo) { + // This should work without including fmt/format.h. +#ifdef FMT_FORMAT_H_ +# error fmt/format.h must not be included in the core test +#endif + std::string s; + fmt::format_to(std::back_inserter(s), "{}", 42); + EXPECT_EQ(s, "42"); +} + TEST(CoreTest, ToStringViewForeignStrings) { using namespace my_ns; using namespace FakeQt;