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

Implement better conversion to strings and better formatting using fmt/std::format #155

Open
3 tasks
KyleVaughn opened this issue May 15, 2024 · 0 comments
Open
3 tasks
Labels

Comments

@KyleVaughn
Copy link
Owner

KyleVaughn commented May 15, 2024

Currently, writing non-string arguments to C-strings or String uses snprintf to write to a buffer. This is not the most performant nor the most elegant solution to this problem. C++-20 adopted std::format (in particular std::format_to_n) for this purpose. We would like to use std::format, but the minimum compiler versions supported by UM2 do not implement std::format.

Since https://github.com/fmtlib/fmt is the reference implementation of std::format and is very widely used, it seems like a reasonable solution is to conditionally include this library. For compilers which support std::format, inclusion of the library can be omitted. In the future if the minimum UM2 standard is bumped to C++23 and we want to drop fmtlib entirely, the only required changes to the code would be the conditional aliasing of fmt vs std in a header.

  • Replace usage of snprintf in String, the logger, and I/O with std::format_to_n
  • Find an alternative to log.hpp's toBuffer. This might just effectively be std::format_to_n.
  • Write a toBuffer equivalent for Vec.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant