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

Const and static version for FMT_VARIADIC #589

Closed
ludekvodicka opened this issue Oct 22, 2017 · 5 comments
Closed

Const and static version for FMT_VARIADIC #589

ludekvodicka opened this issue Oct 22, 2017 · 5 comments

Comments

@ludekvodicka
Copy link
Contributor

Is there any static and const version for FMT_VARIADIC macro?

Static can be "simulated" by passing static to first param:

FMT_VARIADIC(static void, Write, const char *);

but I didn't find a way how to use FMT_VARIADIC for const method.

Thanks

PS: In all other aspects it's a perfect library. Thanks!

@vitaut
Copy link
Contributor

vitaut commented Oct 22, 2017

Is there any static and const version for FMT_VARIADIC macro?

No but it's easy to write them. PRs are welcome =).

If you don't need C++98 support, then I recommend using variadic templates directly instead of FMT_VARIADIC as shown in http://fmtlib.net/latest/api.html#c.FMT_VARIADIC.

@ludekvodicka
Copy link
Contributor Author

Thanks for the reply.

FMT_VARIADIC is currently better way for me although I don't need C++98. The reason is that I can keep method implementation in cpp file and I don't have to move it to header files as the template.

Regarding PR, I will try to implement it, but I'm not sure if I will be able to.

@vitaut
Copy link
Contributor

vitaut commented Oct 22, 2017

FMT_VARIADIC is currently better way for me although I don't need C++98. The reason is that I can keep method implementation in cpp file and I don't have to move it to header files as the template.

You'll be able to do the same in the next version (currently std branch):

// The main formatting function - not a template and can't be defined elsewhere:
std::string vformat(string_view format_str, fmt::args args);

template <typename... Args>
inline std::string format(string_view format_str, const Args & ... args) {
  return vformat(format_str, fmt::make_args(args...));
}

FMT_VARIADIC is for C++-98 compatibility only and will eventually go away.

@ludekvodicka
Copy link
Contributor Author

I understand that the main reason for FMT_VARIADIC is C++98 compatability.

But I think that this macro also helps with better readability and faster development. It's much easier (and resistant to errors) to write FMT_VARIADIC(...) than writing full variadic template each time.

Because of that, it would be great if you will keep this template also after removing C++98 compatibility. On the other side, it's easy to define such macro in my project in case you will decide to remove it.

@ludekvodicka
Copy link
Contributor Author

Tried to implement FMT_VARIADIC_CONST as discussed. Hope it's ok (including test in format-test.cc)

#591

@vitaut vitaut closed this as completed Oct 22, 2017
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