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.
This commit is contained in:
Thomas Novotny 2018-11-20 22:08:54 +01:00
parent 2c6273e617
commit 15eae7cbfa
2 changed files with 23 additions and 26 deletions

View File

@ -573,16 +573,16 @@ void printf(internal::basic_buffer<Char> &buf, basic_string_view<Char> format,
} }
template <typename Buffer> template <typename Buffer>
struct printf_context { struct basic_printf_context_t {
typedef basic_printf_context< typedef basic_printf_context<
std::back_insert_iterator<Buffer>, typename Buffer::value_type> type; std::back_insert_iterator<Buffer>, typename Buffer::value_type> type;
}; };
typedef printf_context<internal::buffer>::type printf_char_context; typedef basic_printf_context_t<internal::buffer>::type printf_context;
typedef printf_context<internal::wbuffer>::type printf_wchar_context; typedef basic_printf_context_t<internal::wbuffer>::type wprintf_context;
typedef basic_format_args<printf_char_context> printf_args; typedef basic_format_args<printf_context> printf_args;
typedef basic_format_args<printf_wchar_context> wprintf_args; typedef basic_format_args<wprintf_context> wprintf_args;
/** /**
\rst \rst
@ -591,7 +591,7 @@ typedef basic_format_args<printf_wchar_context> wprintf_args;
\endrst \endrst
*/ */
template<typename... Args> template<typename... Args>
inline format_arg_store<printf_char_context, Args...> inline format_arg_store<printf_context, Args...>
make_printf_args(const Args &... args) { return {args...}; } make_printf_args(const Args &... args) { return {args...}; }
/** /**
@ -601,14 +601,13 @@ inline format_arg_store<printf_char_context, Args...>
\endrst \endrst
*/ */
template<typename... Args> template<typename... Args>
inline format_arg_store<printf_wchar_context, Args...> inline format_arg_store<wprintf_context, Args...>
make_wprintf_args(const Args &... args) { return {args...}; } make_wprintf_args(const Args &... args) { return {args...}; }
template <typename S, typename Char = FMT_CHAR(S)> template <typename S, typename Char = FMT_CHAR(S)>
inline std::basic_string<Char> inline std::basic_string<Char>
vsprintf(const S &format, vsprintf(const S &format,
basic_format_args<typename printf_context< basic_format_args<typename basic_printf_context_t<
internal::basic_buffer<Char>>::type> args) { internal::basic_buffer<Char>>::type> args) {
basic_memory_buffer<Char> buffer; basic_memory_buffer<Char> buffer;
printf(buffer, to_string_view(format), args); printf(buffer, to_string_view(format), args);
@ -629,7 +628,7 @@ inline FMT_ENABLE_IF_STRING(S, std::basic_string<FMT_CHAR(S)>)
sprintf(const S &format, const Args & ... args) { sprintf(const S &format, const Args & ... args) {
internal::check_format_string<Args...>(format); internal::check_format_string<Args...>(format);
typedef internal::basic_buffer<FMT_CHAR(S)> buffer; typedef internal::basic_buffer<FMT_CHAR(S)> buffer;
typedef typename printf_context<buffer>::type context; typedef typename basic_printf_context_t<buffer>::type context;
format_arg_store<context, Args...> as{ args... }; format_arg_store<context, Args...> as{ args... };
return vsprintf(to_string_view(format), return vsprintf(to_string_view(format),
basic_format_args<context>(as)); basic_format_args<context>(as));
@ -637,7 +636,7 @@ inline FMT_ENABLE_IF_STRING(S, std::basic_string<FMT_CHAR(S)>)
template <typename S, typename Char = FMT_CHAR(S)> template <typename S, typename Char = FMT_CHAR(S)>
inline int vfprintf(std::FILE *f, const S &format, inline int vfprintf(std::FILE *f, const S &format,
basic_format_args<typename printf_context< basic_format_args<typename basic_printf_context_t<
internal::basic_buffer<Char>>::type> args) { internal::basic_buffer<Char>>::type> args) {
basic_memory_buffer<Char> buffer; basic_memory_buffer<Char> buffer;
printf(buffer, to_string_view(format), args); 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) { fprintf(std::FILE *f, const S &format, const Args & ... args) {
internal::check_format_string<Args...>(format); internal::check_format_string<Args...>(format);
typedef internal::basic_buffer<FMT_CHAR(S)> buffer; typedef internal::basic_buffer<FMT_CHAR(S)> buffer;
typedef typename printf_context<buffer>::type context; typedef typename basic_printf_context_t<buffer>::type context;
format_arg_store<context, Args...> as{ args... }; format_arg_store<context, Args...> as{ args... };
return vfprintf(f, to_string_view(format), return vfprintf(f, to_string_view(format),
basic_format_args<context>(as)); basic_format_args<context>(as));
@ -668,7 +667,7 @@ inline FMT_ENABLE_IF_STRING(S, int)
template <typename S, typename Char = FMT_CHAR(S)> template <typename S, typename Char = FMT_CHAR(S)>
inline int vprintf(const S &format, inline int vprintf(const S &format,
basic_format_args<typename printf_context< basic_format_args<typename basic_printf_context_t<
internal::basic_buffer<Char>>::type> args) { internal::basic_buffer<Char>>::type> args) {
return vfprintf(stdout, to_string_view(format), 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) { printf(const S &format_str, const Args & ... args) {
internal::check_format_string<Args...>(format_str); internal::check_format_string<Args...>(format_str);
typedef internal::basic_buffer<FMT_CHAR(S)> buffer; typedef internal::basic_buffer<FMT_CHAR(S)> buffer;
typedef typename printf_context<buffer>::type context; typedef typename basic_printf_context_t<buffer>::type context;
format_arg_store<context, Args...> as{ args... }; format_arg_store<context, Args...> as{ args... };
return vprintf(to_string_view(format_str), return vprintf(to_string_view(format_str),
basic_format_args<context>(as)); basic_format_args<context>(as));
@ -696,7 +695,7 @@ inline FMT_ENABLE_IF_STRING(S, int)
template <typename S, typename Char = FMT_CHAR(S)> template <typename S, typename Char = FMT_CHAR(S)>
inline int vfprintf(std::basic_ostream<Char> &os, inline int vfprintf(std::basic_ostream<Char> &os,
const S &format, const S &format,
basic_format_args<typename printf_context< basic_format_args<typename basic_printf_context_t<
internal::basic_buffer<Char>>::type> args) { internal::basic_buffer<Char>>::type> args) {
basic_memory_buffer<Char> buffer; basic_memory_buffer<Char> buffer;
printf(buffer, to_string_view(format), args); 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) { const S &format_str, const Args & ... args) {
internal::check_format_string<Args...>(format_str); internal::check_format_string<Args...>(format_str);
typedef internal::basic_buffer<FMT_CHAR(S)> buffer; typedef internal::basic_buffer<FMT_CHAR(S)> buffer;
typedef typename printf_context<buffer>::type context; typedef typename basic_printf_context_t<buffer>::type context;
format_arg_store<context, Args...> as{ args... }; format_arg_store<context, Args...> as{ args... };
return vfprintf(os, to_string_view(format_str), return vfprintf(os, to_string_view(format_str),
basic_format_args<context>(as)); basic_format_args<context>(as));

View File

@ -501,7 +501,7 @@ TEST(PrintfTest, OStream) {
} }
TEST(PrintfTest, VPrintf) { TEST(PrintfTest, VPrintf) {
typedef fmt::printf_context<fmt::internal::buffer>::type context; typedef fmt::basic_printf_context_t<fmt::internal::buffer>::type context;
fmt::format_arg_store<context, int> as{42}; fmt::format_arg_store<context, int> as{42};
fmt::basic_format_args<context> args(as); fmt::basic_format_args<context> args(as);
EXPECT_EQ(fmt::vsprintf("%d", args), "42"); EXPECT_EQ(fmt::vsprintf("%d", args), "42");
@ -521,16 +521,14 @@ TEST(PrintfTest, CheckFormatStringRegression) {
TEST(PrintfTest, VSPrintfMakeArgsExample) { TEST(PrintfTest, VSPrintfMakeArgsExample) {
EXPECT_EQ( fmt::printf_args args = fmt::make_printf_args( 42, "something");
"[42] something happened", EXPECT_EQ("[42] something happened",
fmt::vsprintf( fmt::vsprintf( "[%d] %s happened", args));
"[%d] %s happened", fmt::make_printf_args( 42, "something" ) ) );
} }
TEST(PrintfTest, VSPrintfMakeWArgsExample) { TEST( PrintfTest, VSPrintfMakeWArgsExample ) {
EXPECT_EQ( fmt::wprintf_args args = fmt::make_wprintf_args(42, L"something");
L"[42] something happened", EXPECT_EQ(L"[42] something happened",
fmt::vsprintf( fmt::vsprintf(L"[%d] %s happened", args));
L"[%d] %s happened", fmt::make_wprintf_args( 42, L"something" ) ) );
} }