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

FMT_COMPILE vs FMT_STRING vs ""_format() #1772

Closed
leolchat opened this issue Jul 14, 2020 · 2 comments
Closed

FMT_COMPILE vs FMT_STRING vs ""_format() #1772

leolchat opened this issue Jul 14, 2020 · 2 comments

Comments

@leolchat
Copy link
Contributor

The documentation is not extremely clear about the difference between the 3 ways I found to have compile-time format string checks. I would like to try to PR an improvement to the documentation, but first I need to be sure

  • Is there a difference as to what they can check? In my quick survey I could not find an example rejected by one but not the others.
  • Is there a preferred one? Compiler verbose output seems shorter with the FMT_STRING version, but not using a macro is nice, or is the speed boost from FMT_COMPILE usually worth it?

Bonus question, is there one which has a chance to land in std::format?

@vitaut
Copy link
Contributor

vitaut commented Jul 15, 2020

Is there a difference as to what they can check?

Yes, FMT_STRING always does compile-time checks while _format only if a compiler supports UDL templates extensions.

Is there a preferred one?

FMT_STRING and FMT_COMPILE serve different purposes. If you only need checks then use FMT_STRING. If you want to avoid format string parsing overhead then use FMT_COMPILE (this is rarely needed) and note that:

Format string compilation can generate more binary code compared to the default API and is only recommended in places where formatting is a performance bottleneck.

@vitaut vitaut closed this as completed Jul 15, 2020
leolchat added a commit to leolchat/fmt that referenced this issue Jul 15, 2020
Documentation was a bit misleading.
Many people assume that fmt does compile time checks by default, while it requires the use of `FMT_STRING`.
It was also unclear that FMT_COMPILE does the same checks.

fmtlib#1772
@leolchat
Copy link
Contributor Author

Thanks for clarifying. I would say the documentation could be more explicit. I gave it a try.

vitaut pushed a commit that referenced this issue Jul 16, 2020
* Trying to clear ambiguous compile time claims

Documentation was a bit misleading.
Many people assume that fmt does compile time checks by default, while it requires the use of `FMT_STRING`.
It was also unclear that FMT_COMPILE does the same checks.

#1772

* Update api.rst
chenyt9 pushed a commit to MotorolaMobilityLLC/external-fmtlib that referenced this issue May 9, 2023
* Trying to clear ambiguous compile time claims

Documentation was a bit misleading.
Many people assume that fmt does compile time checks by default, while it requires the use of `FMT_STRING`.
It was also unclear that FMT_COMPILE does the same checks.

fmtlib/fmt#1772

* Update api.rst
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