5

Is there a fmtlib API to have something similar to std::to_chars, but also returning a set of string_view for every part of the resulting string - specifically, sign; integer part; decimal part; exponent sign; exponent itself? That could help create own post-processing of e.g. floating-point or integer output, inserting separators (where standard things provided by locale are insufficient) without complexity of parsing the string, and benefit from fast and correct implementation of the library functions. Thanks!

Mike Kaganski
  • 701
  • 6
  • 18

1 Answers1

1

{fmt} can be used as a replacement for to_chars but neither provide an API for accessing components of the output. You could look into https://github.com/jk-jeon/dragonbox which is an implementation of one of the FP formatting algorithms used by {fmt} and it might provide a more low-level API that you are looking for.

vitaut
  • 49,672
  • 25
  • 199
  • 336
  • Thank you very much: +1. It looks very useful; yet, this doesn't seem quite suitable for the task. At least looking through the description and headers, I feel that it is only used to obtain the shortest unambiguous representation; while my question assumes the need to format the string - and indeed, users want arbitrary precision (both shorter and longer than shortest unambiguous). std::to_chars provides that with an overload taking precision ... – Mike Kaganski Oct 01 '21 at 05:32