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

Question: what's the difference between string-like formatters and where are they defined? #3942

Closed
tocic opened this issue Apr 21, 2024 · 2 comments

Comments

@tocic
Copy link

tocic commented Apr 21, 2024

It's not clear for me from the docs if this test project is correct. What are the differences between fmt::formatter<const char*>, fmt::formatter<std::string_view>, fmt::formatter<std::string>? Can I include only fmt/core.h in headers (as in the second example here)? I thought the CE in fmt 10.2.1 (not on trunk) was related to this issue, but now I'm not sure.

@vitaut
Copy link
Contributor

vitaut commented Apr 22, 2024

Those are specializations for different string types. I will investigate why your example doesn't work with std::string formatter but in the meantime you can use a formatter for fmt::string_view which works: https://godbolt.org/z/eo4Y7d7nP.

@vitaut
Copy link
Contributor

vitaut commented Apr 22, 2024

Documented the list of formatter specializations provided by fmt/base.h (which will superseed fmt/core.h): f30f1fd. In general it should be sufficient to use fmt::string_view but if you want a formatter of std::string for some reason you should include fmt/format.h.

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