rapidyaml  0.11.1
parse and emit YAML, and do it fast
Charconv utilities

Lightweight, very fast generic type-safe wrappers for converting individual values to/from strings. More...

Modules

 Get number of digits
 
 Write with known number of digits
 Writes a value without checking the buffer length with regards to the required number of digits to encode the value.
 
 Write a value
 Writes a value without checking the buffer length decimal number – but asserting.
 
 Read a value
 
 itoa: signed to chars
 
 utoa: unsigned to chars
 
 atoi: chars to signed
 
 atou: chars to unsigned
 
 overflows: does a number string overflow a type
 
 ftoa: float32 to chars
 
 dtoa: float64 to chars
 
 atof: chars to float32
 
 atod: chars to float64
 
 xtoa: generic value to chars
 Dispatches to the most appropriate and efficient conversion function.
 
 atox: generic chars to value
 Dispatches to the most appropriate and efficient conversion function.
 
 to_chars: generalized chars to value
 Convert the given value, writing into the string.
 
 from_chars: generalized chars to value
 Read a value from the string, which must be trimmed to the value (ie, no leading/trailing whitespace).
 

Enumerations

enum  c4::RealFormat_e : char { c4::FTOA_FLOAT = 'f' , c4::FTOA_SCIENT = 'e' , c4::FTOA_FLEX = 'g' , c4::FTOA_HEXA = 'a' }
 

Detailed Description

Lightweight, very fast generic type-safe wrappers for converting individual values to/from strings.

These are the main generic functions:

And also some modest brag is in order: these functions are really fast: faster even than C++17 std::to_chars() and std::to_chars(), and many dozens of times faster than the iostream abominations.

For example, here are some benchmark comparisons for from_chars: generalized chars to value (link leads to the main project README, where these results are shown more systematically).

atox,int64_t
g++12, linux Visual Studio 2019
table table captionxtoa,int64_tcaption trthg++12, linux thVisual Studio 2019 trtd
table To parse floating point, c4core uses afastfloata, which is extremely fast, by an even larger factor: table captionatox,floatcaption trthg++12, linux thVisual Studio 2019 trtd
table

Enumeration Type Documentation

◆ RealFormat_e

enum c4::RealFormat_e : char
Warning
Use only the symbol. Do not rely on the type or naked value of this enum.
Enumerator
FTOA_FLOAT 

print the real number in floating point format (like f)

FTOA_SCIENT 

print the real number in scientific format (like e)

FTOA_FLEX 

print the real number in flexible format (like g)

FTOA_HEXA 

print the real number in hexadecimal format (like a)

Definition at line 192 of file charconv.hpp.

192  : char {
193  /** print the real number in floating point format (like %f) */
194  FTOA_FLOAT = 'f',
195  /** print the real number in scientific format (like %e) */
196  FTOA_SCIENT = 'e',
197  /** print the real number in flexible format (like %g) */
198  FTOA_FLEX = 'g',
199  /** print the real number in hexadecimal format (like %a) */
200  FTOA_HEXA = 'a',
201 } RealFormat_e;
RealFormat_e
Definition: charconv.hpp:192
@ FTOA_FLEX
print the real number in flexible format (like g)
Definition: charconv.hpp:198
@ FTOA_SCIENT
print the real number in scientific format (like e)
Definition: charconv.hpp:196
@ FTOA_FLOAT
print the real number in floating point format (like f)
Definition: charconv.hpp:194
@ FTOA_HEXA
print the real number in hexadecimal format (like a)
Definition: charconv.hpp:200