Skip to content

Commit adf698b

Browse files
committed
Add doc page for to_string and string constructor
1 parent 429c0a2 commit adf698b

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

doc/modules/ROOT/nav.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
* xref:cstdio.adoc[]
4444
* xref:functional.adoc[]
4545
* xref:limits.adoc[]
46+
* xref:strings.adoc[]
4647
* xref:config.adoc[]
4748
** xref:config.adoc#configuration_user[User Configuration]
4849
** xref:config.adoc#configuration_automatic[Automatic Configuration]
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
////
2+
Copyright 2025 Matt Borland
3+
Distributed under the Boost Software License, Version 1.0.
4+
https://www.boost.org/LICENSE_1_0.txt
5+
////
6+
7+
[#strings]
8+
= `<string>` support
9+
:idprefix: string_
10+
11+
== Construction from `std::string` and `std::string_view`
12+
13+
Each of the decimal types have constructors that look like the following
14+
15+
[source, c++]
16+
----
17+
namespace boost {
18+
namespace decimal {
19+
20+
class decimal32_t
21+
{
22+
23+
constexpr decimal32_t(const char* str)
24+
25+
#ifndef BOOST_DECIMAL_HAS_STD_STRING_VIEW
26+
inline decimal32_t::decimal32_t(const std::string& str);
27+
#else
28+
constexpr decimal32_t::decimal32_t(std::string_view str);
29+
#endif
30+
};
31+
32+
} // namespace decimal
33+
} // namespace boost
34+
----
35+
36+
These constructors allow for construction from C-strings, `std::string`, and from `std::string_view` when available.
37+
They construct the value as though calling `from_chars` without a specified format.
38+
If the input string is invalid these constructors will `throw std::runtime_error`.
39+
If you are using a no exceptions environment instead of throwing the constructor will return a Quiet NAN.
40+
41+
== `to_string`
42+
43+
[source, c++]
44+
----
45+
#include <boost/decimal/string.hpp>
46+
47+
namespace boost {
48+
namespace decimal {
49+
50+
template <typename DecimalType>
51+
std::string to_string(const DecimalType value)
52+
53+
} // namespace decimal
54+
} // namespace boost
55+
----
56+
57+
The `to_string` format returns a `std::string` of the decimal value formated as though using `to_chars` with general formatting, and no specified precision.

0 commit comments

Comments
 (0)