Skip to content

Commit 38f6249

Browse files
committed
Add to docs
1 parent f29dec7 commit 38f6249

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

doc/decimal/charconv.adoc

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
----

0 commit comments

Comments
 (0)