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

Replacing fmt lib with std::format #469

Open
Woazboat opened this issue Feb 28, 2025 · 3 comments
Open

Replacing fmt lib with std::format #469

Woazboat opened this issue Feb 28, 2025 · 3 comments

Comments

@Woazboat
Copy link
Contributor

Woazboat commented Feb 28, 2025

Creating this issue mostly for documenting the challenges involved, since it came up as a potential change after switching to C++20.

Obviously depends on at least C++20 #323

  • Replacing instances of fmt::format is trivial and just requires a rename to std::format
  • FMT_COMPILE macros for optimized fmt format strings can simply be removed. std::format is already compile time.
  • Some code snippets currently choose between different more optimized implementations depending on the version of the fmt lib. These could be simplified and replaced by the equivalent functions which are guaranteed to exist in std <format>.
  • Custom fmt::formatter helpers (for e.g. the api06::id_version type) need to be changed to std::formatter.
  • fmt::join() is currently used in several places to format ranges with separators ("1,2,3,4"). There is unfortunately no direct analogue available in C++20. Range formatting was not included in C++20 and was only introduced in C++23. It is also not yet supported by GCC libstdc++.
  • std::format requires at least GCC 13, Debian stable still ships GCC 12
@Woazboat
Copy link
Contributor Author

Woazboat commented Feb 28, 2025

https://github.com/Woazboat/openstreetmap-cgimap/tree/c%2B%2B20_replace_fmt has all changes except a replacement for fmt::join

@mmd-osm
Copy link
Collaborator

mmd-osm commented Feb 28, 2025

A simplified replacement for fmt::join() might be good enough to format a few ids: https://cpp.godbolt.org/z/eovh9re8v

@Woazboat
Copy link
Contributor Author

Woazboat commented Mar 4, 2025

PR #474 should be revisited when support for GCC 12 is no longer required (see initial comment).

@mmd-osm mmd-osm added this to the Ideas for future enhancements milestone Mar 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants