From c606eaa166865e9e452638e8afe8e8f1d99ab7dd Mon Sep 17 00:00:00 2001 From: clyne Date: Sun, 28 Jun 2020 09:27:46 -0400 Subject: [PATCH] Update readme for f_to_string --- README.md | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f2c55e1..1dd7663 100644 --- a/README.md +++ b/README.md @@ -6,10 +6,11 @@ * Supports converting to any base between 2 and 36 inclusive * No external dependencies, only includes `type_traits` for template parameter checking * Supports custom character types, e.g. `to_string<123, 10, wchar_t>` +* C++20: Supports floating-point-to-string conversion with `f_to_string` **How to use:** -This single header file provides a `to_string` utility, which may be used as below: +The file `to_string.hpp` provides a `to_string` utility, which may be used as below: ```cpp const char *number = to_string<2147483648999954564, 16>; // produces "1DCD65003B9A1884" @@ -22,6 +23,13 @@ With `to_string`, all that will be found in program disassembly are the resultin Try it [on Compiler Explorer](https://godbolt.org/z/T-MFoh). +`f_to_string.hpp`, requiring C++20, provides an `f_to_string` utility for floating-point conversion: + +``` +puts(f_to_string<3.1415926>); // Defaults to 5-point precision: "3.14159" +puts(f_to_string<{3.1415926, 7}>); // Specify precision: "3.1415926" +``` + # How it works The basic structure of `to_string` is shown below: @@ -29,7 +37,7 @@ The basic structure of `to_string` is shown below: ```cpp template struct to_string_t { - char_type buf[]; // Size selection explained later. + char_type buf[]; // Array size determination explained later. constexpr to_string_t() {} // Converts the integer to a string stored in buf. constexpr operator char_type *() {} // These allow for the object to be implicitly converted constexpr operator const char_type *() {} // to a character pointer.