File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed
Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -67,3 +67,44 @@ NOTE: `BOOST_DECIMAL_CONSTEXPR` is defined if:
6767 - `\\__GNUC__` >= 9
6868 - Compiler has: `__builtin_is_constant_evaluated()`
6969 - C++20 support with: `std::is_constant_evaluated()`
70+
71+ The library offers an additional feature for sizing buffers without specified precision and in general format
72+ [source, c++]
73+ ----
74+ namespace boost {
75+ namespace decimal {
76+
77+ template <typename T>
78+ struct limits
79+ {
80+ static constexpr int max_chars;
81+ }
82+
83+ } //namespace decimal
84+ } //namespace boost
85+ ----
86+
87+ The member can then be used to size buffers such as:
88+
89+ [source, c++]
90+ ----
91+ #include <boost/decimal.hpp>
92+ #include <iostream>
93+
94+ int main()
95+ {
96+ using namespace boost::decimal;
97+
98+ decimal32 val {5, -1};
99+
100+ char buffer[limits<T>::max_chars];
101+
102+ auto r_to = to_chars(buffer, buffer + sizeof(buffer), val);
103+ *r_to.ptr = '\0';
104+
105+ std::cout << buffer << std::endl;
106+
107+ return 0;
108+ }
109+
110+ ----
You can’t perform that action at this time.
0 commit comments