Skip to content

Commit b6ada23

Browse files
committed
Add formatting limits to the documentation page of charconv
1 parent 335e547 commit b6ada23

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

doc/modules/ROOT/pages/charconv.adoc

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -159,25 +159,41 @@ IMPORTANT: Same as `from_chars`, `boost::decimal::to_chars` will return a `std::
159159
The library offers an additional feature for sizing buffers without specified precision and in general format
160160

161161
[#charconv_limits]
162-
== limits
162+
== Formatting Limits
163163
[source, c++]
164164
----
165165
#include <boost/decimal/charconv.hpp>
166166
167167
namespace boost {
168168
namespace decimal {
169169
170-
template <typename T>
171-
struct limits
170+
template <typename DecimalType, int Precision = std::numeric_limits<DecimalType>::max_digits10>
171+
class formatting_limits
172172
{
173-
static constexpr int max_chars;
174-
}
173+
public:
174+
175+
static constexpr std::size_t scientific_format_max_chars;
176+
177+
static constexpr std::size_t fixed_format_max_chars;
178+
179+
static constexpr std::size_t hex_format_max_chars;
180+
181+
static constexpr std::size_t cohort_preserving_scientific_max_chars;
182+
183+
static constexpr std::size_t general_format_max_chars;
184+
185+
static constexpr std::size_t max_chars;
186+
};
175187
176188
} //namespace decimal
177189
} //namespace boost
178190
----
179191

180-
The member can then be used to size buffers such as:
192+
This class allows you to size buffers for `to_chars` without have to arbitrarily guess what size you need it to be.
193+
The `Precision` is defaulted to the maximum precision of the type, which is the same assumption that is made when you use `to_chars` with an unspecified precision.
194+
The `max_chars` variable is the largest of the 5 specified `chars_format` options.
195+
196+
The members can then be used to size buffers such as:
181197

182198
[source, c++]
183199
----
@@ -190,7 +206,7 @@ int main()
190206
191207
decimal32_t val {5, -1};
192208
193-
char buffer[limits<decimal32_t>::max_chars];
209+
char buffer[formatting_limits<decimal32_t>::max_chars];
194210
195211
auto r_to = to_chars(buffer, buffer + sizeof(buffer), val);
196212
*r_to.ptr = '\0';

0 commit comments

Comments
 (0)