From 15eae7cbfab0acdb3ae195b41e9ad1b53c5d5c51 Mon Sep 17 00:00:00 2001 From: Thomas Novotny Date: Tue, 20 Nov 2018 22:08:54 +0100 Subject: [PATCH] fixed review issues rename printf_char_context to printf_context remane printf_wchar_context to wprintf_context renamed the old printf_context template to basic_printf_context_t. the original wish was to rename it basic_printf_context, but that clashed with the name of the inner typedef. this style matches the format_context_t struct. try to fix compile errors for older gcc versions by storing a temporary. --- include/fmt/printf.h | 31 +++++++++++++++---------------- test/printf-test.cc | 18 ++++++++---------- 2 files changed, 23 insertions(+), 26 deletions(-) diff --git a/include/fmt/printf.h b/include/fmt/printf.h index de7036b3..005df5f1 100644 --- a/include/fmt/printf.h +++ b/include/fmt/printf.h @@ -573,16 +573,16 @@ void printf(internal::basic_buffer &buf, basic_string_view format, } template -struct printf_context { +struct basic_printf_context_t { typedef basic_printf_context< std::back_insert_iterator, typename Buffer::value_type> type; }; -typedef printf_context::type printf_char_context; -typedef printf_context::type printf_wchar_context; +typedef basic_printf_context_t::type printf_context; +typedef basic_printf_context_t::type wprintf_context; -typedef basic_format_args printf_args; -typedef basic_format_args wprintf_args; +typedef basic_format_args printf_args; +typedef basic_format_args wprintf_args; /** \rst @@ -591,7 +591,7 @@ typedef basic_format_args wprintf_args; \endrst */ template -inline format_arg_store +inline format_arg_store make_printf_args(const Args &... args) { return {args...}; } /** @@ -601,14 +601,13 @@ inline format_arg_store \endrst */ template -inline format_arg_store +inline format_arg_store make_wprintf_args(const Args &... args) { return {args...}; } - template inline std::basic_string vsprintf(const S &format, - basic_format_args>::type> args) { basic_memory_buffer buffer; printf(buffer, to_string_view(format), args); @@ -629,7 +628,7 @@ inline FMT_ENABLE_IF_STRING(S, std::basic_string) sprintf(const S &format, const Args & ... args) { internal::check_format_string(format); typedef internal::basic_buffer buffer; - typedef typename printf_context::type context; + typedef typename basic_printf_context_t::type context; format_arg_store as{ args... }; return vsprintf(to_string_view(format), basic_format_args(as)); @@ -637,7 +636,7 @@ inline FMT_ENABLE_IF_STRING(S, std::basic_string) template inline int vfprintf(std::FILE *f, const S &format, - basic_format_args>::type> args) { basic_memory_buffer buffer; printf(buffer, to_string_view(format), args); @@ -660,7 +659,7 @@ inline FMT_ENABLE_IF_STRING(S, int) fprintf(std::FILE *f, const S &format, const Args & ... args) { internal::check_format_string(format); typedef internal::basic_buffer buffer; - typedef typename printf_context::type context; + typedef typename basic_printf_context_t::type context; format_arg_store as{ args... }; return vfprintf(f, to_string_view(format), basic_format_args(as)); @@ -668,7 +667,7 @@ inline FMT_ENABLE_IF_STRING(S, int) template inline int vprintf(const S &format, - basic_format_args>::type> args) { return vfprintf(stdout, to_string_view(format), args); } @@ -687,7 +686,7 @@ inline FMT_ENABLE_IF_STRING(S, int) printf(const S &format_str, const Args & ... args) { internal::check_format_string(format_str); typedef internal::basic_buffer buffer; - typedef typename printf_context::type context; + typedef typename basic_printf_context_t::type context; format_arg_store as{ args... }; return vprintf(to_string_view(format_str), basic_format_args(as)); @@ -696,7 +695,7 @@ inline FMT_ENABLE_IF_STRING(S, int) template inline int vfprintf(std::basic_ostream &os, const S &format, - basic_format_args>::type> args) { basic_memory_buffer buffer; printf(buffer, to_string_view(format), args); @@ -719,7 +718,7 @@ inline FMT_ENABLE_IF_STRING(S, int) const S &format_str, const Args & ... args) { internal::check_format_string(format_str); typedef internal::basic_buffer buffer; - typedef typename printf_context::type context; + typedef typename basic_printf_context_t::type context; format_arg_store as{ args... }; return vfprintf(os, to_string_view(format_str), basic_format_args(as)); diff --git a/test/printf-test.cc b/test/printf-test.cc index 414314c9..a4d840e8 100644 --- a/test/printf-test.cc +++ b/test/printf-test.cc @@ -501,7 +501,7 @@ TEST(PrintfTest, OStream) { } TEST(PrintfTest, VPrintf) { - typedef fmt::printf_context::type context; + typedef fmt::basic_printf_context_t::type context; fmt::format_arg_store as{42}; fmt::basic_format_args args(as); EXPECT_EQ(fmt::vsprintf("%d", args), "42"); @@ -521,16 +521,14 @@ TEST(PrintfTest, CheckFormatStringRegression) { TEST(PrintfTest, VSPrintfMakeArgsExample) { - EXPECT_EQ( - "[42] something happened", - fmt::vsprintf( - "[%d] %s happened", fmt::make_printf_args( 42, "something" ) ) ); + fmt::printf_args args = fmt::make_printf_args( 42, "something"); + EXPECT_EQ("[42] something happened", + fmt::vsprintf( "[%d] %s happened", args)); } -TEST(PrintfTest, VSPrintfMakeWArgsExample) { - EXPECT_EQ( - L"[42] something happened", - fmt::vsprintf( - L"[%d] %s happened", fmt::make_wprintf_args( 42, L"something" ) ) ); +TEST( PrintfTest, VSPrintfMakeWArgsExample ) { + fmt::wprintf_args args = fmt::make_wprintf_args(42, L"something"); + EXPECT_EQ(L"[42] something happened", + fmt::vsprintf(L"[%d] %s happened", args)); }