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

Manually construct ArgList and pass to fmt::print #401

Closed
Mark-Joy opened this issue Oct 27, 2016 · 5 comments
Closed

Manually construct ArgList and pass to fmt::print #401

Mark-Joy opened this issue Oct 27, 2016 · 5 comments

Comments

@Mark-Joy
Copy link

Hello,

Is there a way to manually construct the ArgList, add new arg to ArgList and then pass it to fmt::print.
Something like:

fmt::ArgList argl(int val1, string str2, double db3);
argl.add(string str4);

fmt::print(string str, argl)

Thank you

@vitaut
Copy link
Contributor

vitaut commented Oct 28, 2016

Yes, although this method relies on internal APIs at the moment: #330 (comment)

@vitaut vitaut closed this as completed Oct 28, 2016
@Mark-Joy
Copy link
Author

Mark-Joy commented May 7, 2018

Hello,

I just updated latest version of fmtlib to my project and the old code won't compile. How to achieve the same thing as #330 (comment) with latest version?
Can you also make this officially supported without using internal api?

enum {NUM_ARGS = 2};
  typedef fmt::internal::ArgArray<2> ArgArray;
  typename ArgArray::Type array;
  array[0] = ArgArray::template make<fmt::BasicFormatter<char> >(42);
  array[1] = ArgArray::template make<fmt::BasicFormatter<char> >(43);
  fmt::ArgList args(fmt::internal::make_type(42, 43), array);
  fmt::printf("%d %d", args);

@vitaut
Copy link
Contributor

vitaut commented May 9, 2018

@Mark-Joy, it is much simpler in the latest version and you don't need to use internal APIs any more:

  fmt::vprintf("%d %d", fmt::make_printf_args(42, 43));

Compiler Explorer: https://godbolt.org/g/74wSR7

@Mark-Joy
Copy link
Author

Mark-Joy commented May 9, 2018

@vitaut, Thank you for your answer.
I suppose I would use make_format_args for:

fmt::vprint("{} {}", fmt::make_format_args(42, 43));

How about constructing arglist using a for loop as in this comment ?

@vitaut
Copy link
Contributor

vitaut commented May 12, 2018

@Mark-Joy there is no API for constructing arglist in a for loop unfortunately. It should be possible to write one, but noone has done it yet.

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

No branches or pull requests

2 participants