Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fmtlib: an API to return parts of the formatted number in result string?

Tags:

c++

fmt

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!

like image 930
Mike Kaganski Avatar asked Nov 06 '22 00:11

Mike Kaganski


1 Answers

{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.

like image 112
vitaut Avatar answered Nov 15 '22 05:11

vitaut