Skip to content

Re-implement built-in conversions using std::format_to_n() / std::formatted_size()? #1016

@jtv

Description

@jtv

It looks to me like we could easily replace most conversions from built-in arithmetic types to strings with std::format_to_n() and the corresponding budgeting with std::formatted_size().

Benefits:

  • Less dichotomy between integral and floating-point types.
  • Ditch complex buffer-budgeting code.
  • Trust standard library optimisations over custom cleverness.
  • Just maybe get rid of the horrible workarounds for missing floating-point charconv support.

In all honesty, I was quite proud of my trick of writing integer conversions back-to-front in to_buf() and just not caring whether the string would start at the beginning of the buffer. But it's doubtful that I'd be getting much better performance than a good standard-library implementation.

Risks/costs:

  • Need to figure out levels of floating-point support from scratch.
  • Feels wasteful to have the library parse "{}" format strings every time.
  • Missing out on constexpr.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions