Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add make_printf_args and make_wprintf_args functions #934

Merged
merged 8 commits into from
Nov 22, 2018
Merged

add make_printf_args and make_wprintf_args functions #934

merged 8 commits into from
Nov 22, 2018

Conversation

tnovotny
Copy link
Contributor

Add utitlity functions to allow the easy creation of fmt::printf_args and fmt::wprintf_args.

add minimal test for make_printf_args and make_wprintf_args to printf-test.cc
-removed Context parameter from make_printf_args and make_wprintf_args
-renamed tests
@tnovotny
Copy link
Contributor Author

Hmm, not sure why the g++ 4.8/4.4 are failing. Any ideas?

Copy link
Contributor

@vitaut vitaut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. Mostly looks good, just small comments inline and the new tests don't compile on older gcc because implicit conversion to printf_args is not working there. You need to do something like (see the implementation of sprintf:

  format_arg_store<context, Args...> as{args...};
  vsprintf(..., basic_format_args<context>(as));

typedef basic_format_args<printf_context<internal::buffer>::type> printf_args;
typedef basic_format_args<printf_context<internal::wbuffer>::type> wprintf_args;
typedef printf_context<internal::buffer>::type printf_char_context;
typedef printf_context<internal::wbuffer>::type printf_wchar_context;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

printf_char_context and printf_wchar_context should be called printf_context and wprintf_context for consistency with format_context and wformat_context. The old printf_context template should be renamed to basic_printf_context.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up using basic_printf_context_t because it caused a name conflict with the inner typedef. That naming style is also with the format context

template <typename OutputIt, typename Char = char>
//using format_context_t = basic_format_context<OutputIt, Char>;
struct format_context_t { typedef basic_format_context<OutputIt, Char> type; };

I hope that is ok with you.

@@ -518,3 +518,19 @@ void check_format_string_regression(fmt::string_view s, const Args&... args) {
TEST(PrintfTest, CheckFormatStringRegression) {
check_format_string_regression("%c%s", 'x', "");
}


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: no need for an extra empty line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

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.
…xample again

storing the value in a temporary causes even more failures
#define out problematic test for gcc 4
@tnovotny
Copy link
Contributor Author

I don't know how to make the problematic tests pass for the gcc versions and I want a tests that mirrors the intended usage, so I #defined it out for gcc 4, for lack of a better idea.

@tnovotny
Copy link
Contributor Author

In the additional test, the type returned by fmt seems to be different for msvc 2013. It returns the string literals as const array where in all of the other cases it isn't const. That kinda seems like a bug in fmtlib.

@@ -518,3 +517,43 @@ void check_format_string_regression(fmt::string_view s, const Args&... args) {
TEST(PrintfTest, CheckFormatStringRegression) {
check_format_string_regression("%c%s", 'x', "");
}

TEST( PrintfTest, VSPrintfMakeArgsExample ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: spaces after ( and before ) are not needed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed all the superfluous spaces clang formatting introduced. I think I got them all.

@vitaut
Copy link
Contributor

vitaut commented Nov 21, 2018

There are a few compile errors on MSVC2013: https://ci.appveyor.com/project/vitaut/fmt/builds/20446501/job/tu84x312yjrwp6h7

@vitaut vitaut merged commit e37d6a9 into fmtlib:master Nov 22, 2018
@vitaut
Copy link
Contributor

vitaut commented Nov 22, 2018

Merged, thanks!

@vitaut
Copy link
Contributor

vitaut commented Aug 18, 2019

@tnovotny, could you please review the updated CONTIBUTING document, particularly the part about licensing, and let me know if you agree with it being applied to your contributions to {fmt}? The library is likely to be relicensed (#1073) so I'm collecting approval from all earlier contributors. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants