Skip to content

Commit f5e1971

Browse files
authored
Merge pull request #167 from boostorg/166
2 parents 0e3d9cf + 1a83f89 commit f5e1971

10 files changed

+51
-51
lines changed

doc/charconv/to_chars.adoc

+6-6
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ https://www.boost.org/LICENSE_1_0.txt
1010
== to_chars overview
1111

1212
`to_chars` is a set of functions that attempts to convert `value` into a character buffer specified by `[first, last)`.
13-
The result of `to_chars` is `to_chars_result` which on success returns `ptr` equal to one-past-the-end of the characters written and `ec == std::errc()` and on failure returns `std::errc::result_out_of_range` and `ptr == last`.
13+
The result of `to_chars` is `to_chars_result` which on success returns `ptr` equal to one-past-the-end of the characters written and `ec == std::errc()` and on failure returns `std::errc::value_too_large` and `ptr == last`.
1414
`to_chars` does not null-terminate the returned characters.
1515

1616
== Definitions
@@ -55,7 +55,7 @@ See <<chars_format overview>> for description.
5555
|===
5656
|Return Value | Description
5757
|`std::errc()` | Successful Parsing
58-
| `std::errc::result_out_of_range` | 1) Overflow
58+
| `std::errc::value_too_large` | 1) Overflow
5959

6060
2) Underflow
6161
|===
@@ -138,14 +138,14 @@ std::cout << "U: " << buffer_u << "\nV: " << buffer_v << std::endl;
138138
139139
----
140140

141-
=== std::errc::result_out_of_range
141+
=== std::errc::value_too_large
142142
==== Integral
143143
[source, c++]
144144
----
145145
char buffer[3] {};
146146
int v = -1234;
147147
to_chars_result r = boost::charconv::to_chars(buffer, buffer + sizeof(buffer) - 1, v, 16);
148-
assert(r.ec == std::errc::result_out_of_range);
148+
assert(r.ec == std::errc::value_too_large);
149149
assert(!r); // Same as above but less verbose. Added in C++26.
150150
----
151151
==== Floating Point
@@ -154,8 +154,8 @@ assert(!r); // Same as above but less verbose. Added in C++26.
154154
char buffer[3] {};
155155
double v = 1.2345;
156156
auto r = boost::charconv::to_chars(buffer, buffer + sizeof(buffer) - 1, v);
157-
assert(r.ec == std::errc::result_out_of_range);
157+
assert(r.ec == std::errc::value_too_large);
158158
assert(!r); // Same as above but less verbose. Added in C++26.
159159
----
160160

161-
In the event of `std::errc::result_out_of_range`, to_chars_result.ptr is equal to `last`
161+
In the event of `std::errc::value_too_large`, to_chars_result.ptr is equal to `last`

include/boost/charconv/detail/dragonbox/dragonbox.hpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -2605,7 +2605,7 @@ namespace to_chars_detail {
26052605
}
26062606
else
26072607
{
2608-
return {last, std::errc::result_out_of_range};
2608+
return {last, std::errc::value_too_large};
26092609
}
26102610
}
26112611
}
@@ -2628,7 +2628,7 @@ namespace to_chars_detail {
26282628
}
26292629
else
26302630
{
2631-
return {last, std::errc::result_out_of_range};
2631+
return {last, std::errc::value_too_large};
26322632
}
26332633
}
26342634
else
@@ -2677,7 +2677,7 @@ namespace to_chars_detail {
26772677
}
26782678
else
26792679
{
2680-
return {last, std::errc::result_out_of_range};
2680+
return {last, std::errc::value_too_large};
26812681
}
26822682
}
26832683
else
@@ -2689,7 +2689,7 @@ namespace to_chars_detail {
26892689
}
26902690
else
26912691
{
2692-
return {last, std::errc::result_out_of_range};
2692+
return {last, std::errc::value_too_large};
26932693
}
26942694
}
26952695
}
@@ -2702,7 +2702,7 @@ namespace to_chars_detail {
27022702
}
27032703
else
27042704
{
2705-
return {last, std::errc::result_out_of_range};
2705+
return {last, std::errc::value_too_large};
27062706
}
27072707
}
27082708
}

include/boost/charconv/detail/dragonbox/floff.hpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -1308,7 +1308,7 @@ BOOST_CHARCONV_SAFEBUFFERS to_chars_result floff(const double x, const int preci
13081308
{
13091309
if (first >= last)
13101310
{
1311-
return {last, std::errc::result_out_of_range};
1311+
return {last, std::errc::value_too_large};
13121312
}
13131313

13141314
auto buffer_size = static_cast<std::size_t>(last - first);
@@ -1339,7 +1339,7 @@ BOOST_CHARCONV_SAFEBUFFERS to_chars_result floff(const double x, const int preci
13391339

13401340
if (buffer_size < inf_chars)
13411341
{
1342-
return {last, std::errc::result_out_of_range};
1342+
return {last, std::errc::value_too_large};
13431343
}
13441344

13451345
std::memcpy(buffer, "inf", inf_chars); // NOLINT : Specifically not null-terminating
@@ -1359,7 +1359,7 @@ BOOST_CHARCONV_SAFEBUFFERS to_chars_result floff(const double x, const int preci
13591359

13601360
if (buffer_size < nan_chars)
13611361
{
1362-
return {last, std::errc::result_out_of_range};
1362+
return {last, std::errc::value_too_large};
13631363
}
13641364

13651365
std::memcpy(buffer, "nan", nan_chars); // NOLINT : Specifically not null-terminating
@@ -1371,7 +1371,7 @@ BOOST_CHARCONV_SAFEBUFFERS to_chars_result floff(const double x, const int preci
13711371

13721372
if (buffer_size < neg_nan_chars)
13731373
{
1374-
return {last, std::errc::result_out_of_range};
1374+
return {last, std::errc::value_too_large};
13751375
}
13761376

13771377
std::memcpy(buffer, "nan(ind)", neg_nan_chars); // NOLINT : Specifically not null-terminating
@@ -1384,7 +1384,7 @@ BOOST_CHARCONV_SAFEBUFFERS to_chars_result floff(const double x, const int preci
13841384

13851385
if (buffer_size < snan_chars)
13861386
{
1387-
return {last, std::errc::result_out_of_range};
1387+
return {last, std::errc::value_too_large};
13881388
}
13891389

13901390
std::memcpy(buffer, "nan(snan)", snan_chars); // NOLINT : Specifically not null-terminating
@@ -1419,7 +1419,7 @@ BOOST_CHARCONV_SAFEBUFFERS to_chars_result floff(const double x, const int preci
14191419

14201420
if (buffer_size < zero_chars)
14211421
{
1422-
return {last, std::errc::result_out_of_range};
1422+
return {last, std::errc::value_too_large};
14231423
}
14241424

14251425
std::memcpy(buffer, "0e+00", zero_chars);
@@ -1429,7 +1429,7 @@ BOOST_CHARCONV_SAFEBUFFERS to_chars_result floff(const double x, const int preci
14291429
{
14301430
if (buffer_size < static_cast<std::size_t>(precision) + 6U)
14311431
{
1432-
return {last, std::errc::result_out_of_range};
1432+
return {last, std::errc::value_too_large};
14331433
}
14341434

14351435
std::memcpy(buffer, "0.", 2); // NOLINT : Specifically not null-terminating
@@ -1460,7 +1460,7 @@ BOOST_CHARCONV_SAFEBUFFERS to_chars_result floff(const double x, const int preci
14601460

14611461
if (buffer_size < static_cast<std::size_t>(remaining_digits))
14621462
{
1463-
return {last, std::errc::result_out_of_range};
1463+
return {last, std::errc::value_too_large};
14641464
}
14651465

14661466
/////////////////////////////////////////////////////////////////////////////////////////////////

include/boost/charconv/detail/ryu/ryu_generic_128.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ static inline int generic_to_chars_fixed(const struct floating_decimal_128 v, ch
401401
// Option 2: Append 0s to the end of the number until we get the proper output
402402
if (current_len + v.exponent > result_size)
403403
{
404-
return -static_cast<int>(std::errc::result_out_of_range);
404+
return -static_cast<int>(std::errc::value_too_large);
405405
}
406406

407407
memset(r.ptr, '0', static_cast<std::size_t>(v.exponent));
@@ -419,7 +419,7 @@ static inline int generic_to_chars_fixed(const struct floating_decimal_128 v, ch
419419
// Option 4: Leading 0s
420420
if (-v.exponent + 2 > result_size)
421421
{
422-
return -static_cast<int>(std::errc::result_out_of_range);
422+
return -static_cast<int>(std::errc::value_too_large);
423423
}
424424

425425
memmove(result - v.exponent - current_len + 2, result, static_cast<std::size_t>(current_len));
@@ -480,7 +480,7 @@ static inline int generic_to_chars(const struct floating_decimal_128 v, char* re
480480

481481
if (index + olength > static_cast<size_t>(result_size))
482482
{
483-
return -static_cast<int>(std::errc::result_out_of_range);
483+
return -static_cast<int>(std::errc::value_too_large);
484484
}
485485
else if (olength == 0)
486486
{

include/boost/charconv/detail/to_chars_integer_impl.hpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ BOOST_CHARCONV_CONSTEXPR to_chars_result to_chars_integer_impl(char* first, char
130130

131131
if (converted_value_digits > user_buffer_size)
132132
{
133-
return {last, std::errc::result_out_of_range};
133+
return {last, std::errc::value_too_large};
134134
}
135135

136136
decompose32(converted_value, buffer);
@@ -151,7 +151,7 @@ BOOST_CHARCONV_CONSTEXPR to_chars_result to_chars_integer_impl(char* first, char
151151

152152
if (converted_value_digits > user_buffer_size)
153153
{
154-
return {last, std::errc::result_out_of_range};
154+
return {last, std::errc::value_too_large};
155155
}
156156

157157
if (is_negative)
@@ -258,7 +258,7 @@ BOOST_CHARCONV_CONSTEXPR to_chars_result to_chars_128integer_impl(char* first, c
258258

259259
if (converted_value_digits > user_buffer_size)
260260
{
261-
return {last, std::errc::result_out_of_range};
261+
return {last, std::errc::value_too_large};
262262
}
263263

264264
if (is_negative)
@@ -409,7 +409,7 @@ BOOST_CHARCONV_CONSTEXPR to_chars_result to_chars_integer_impl(char* first, char
409409

410410
if (num_chars > output_length)
411411
{
412-
return {last, std::errc::result_out_of_range};
412+
return {last, std::errc::value_too_large};
413413
}
414414

415415
boost::charconv::detail::memcpy(first, buffer + (buffer_size - static_cast<unsigned long>(num_chars)),

src/to_chars.cpp

+11-11
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ namespace boost { namespace charconv { namespace detail { namespace to_chars_det
272272
const std::ptrdiff_t total_length = total_buffer_length(9, exponent, false);
273273
if (total_length > (last - first))
274274
{
275-
return {last, std::errc::result_out_of_range};
275+
return {last, std::errc::value_too_large};
276276
}
277277

278278
// Print significand.
@@ -315,7 +315,7 @@ namespace boost { namespace charconv { namespace detail { namespace to_chars_det
315315
const std::ptrdiff_t total_length = total_buffer_length(17, exponent, false);
316316
if (total_length > (last - first))
317317
{
318-
return {last, std::errc::result_out_of_range};
318+
return {last, std::errc::value_too_large};
319319
}
320320

321321
// Print significand by decomposing it into a 9-digit block and a 8-digit block.
@@ -593,7 +593,7 @@ boost::charconv::to_chars_result boost::charconv::to_chars(char* first, char* la
593593
}
594594
else
595595
{
596-
return {last, std::errc::result_out_of_range};
596+
return {last, std::errc::value_too_large};
597597
}
598598
}
599599
#endif
@@ -603,7 +603,7 @@ boost::charconv::to_chars_result boost::charconv::to_chars(char* first, char* la
603603
auto real_precision = boost::charconv::detail::get_real_precision<long double>(precision);
604604
if (buffer_size < real_precision || first > last)
605605
{
606-
return {last, std::errc::result_out_of_range};
606+
return {last, std::errc::value_too_large};
607607
}
608608

609609
if (fmt == boost::charconv::chars_format::general || fmt == boost::charconv::chars_format::scientific)
@@ -629,9 +629,9 @@ boost::charconv::to_chars_result boost::charconv::to_chars(char* first, char* la
629629
{
630630
return { first + num_chars, std::errc() };
631631
}
632-
else if (num_chars == -static_cast<int>(std::errc::result_out_of_range))
632+
else if (num_chars == -static_cast<int>(std::errc::value_too_large))
633633
{
634-
return { last, std::errc::result_out_of_range };
634+
return { last, std::errc::value_too_large };
635635
}
636636
}
637637

@@ -686,7 +686,7 @@ boost::charconv::to_chars_result boost::charconv::to_chars(char* first, char* la
686686
// Sanity check our bounds
687687
if (first >= last)
688688
{
689-
return {last, std::errc::result_out_of_range};
689+
return {last, std::errc::value_too_large};
690690
}
691691

692692
char* const original_first = first;
@@ -705,7 +705,7 @@ boost::charconv::to_chars_result boost::charconv::to_chars(char* first, char* la
705705
auto real_precision = boost::charconv::detail::get_real_precision<__float128>(precision);
706706
if (buffer_size < real_precision || first > last)
707707
{
708-
return {last, std::errc::result_out_of_range};
708+
return {last, std::errc::value_too_large};
709709
}
710710

711711
if ((fmt == boost::charconv::chars_format::general || fmt == boost::charconv::chars_format::scientific))
@@ -719,7 +719,7 @@ boost::charconv::to_chars_result boost::charconv::to_chars(char* first, char* la
719719
}
720720
else if (num_chars == -1)
721721
{
722-
return {last, std::errc::result_out_of_range};
722+
return {last, std::errc::value_too_large};
723723
}
724724
}
725725
else if (fmt == boost::charconv::chars_format::hex)
@@ -735,9 +735,9 @@ boost::charconv::to_chars_result boost::charconv::to_chars(char* first, char* la
735735
{
736736
return { first + num_chars, std::errc() };
737737
}
738-
else if (num_chars == -static_cast<int>(std::errc::result_out_of_range))
738+
else if (num_chars == -static_cast<int>(std::errc::value_too_large))
739739
{
740-
return { last, std::errc::result_out_of_range };
740+
return { last, std::errc::value_too_large };
741741
}
742742
}
743743

src/to_chars_float_impl.hpp

+9-9
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ inline to_chars_result to_chars_nonfinite(char* first, char* last, Real value, i
8787
else
8888
{
8989
// Avoid buffer overflow
90-
return { first, std::errc::result_out_of_range };
90+
return { first, std::errc::value_too_large };
9191
}
9292

9393
}
@@ -107,7 +107,7 @@ inline to_chars_result to_chars_nonfinite(char* first, char* last, Real value, i
107107
else
108108
{
109109
// Avoid buffer overflow
110-
return { first, std::errc::result_out_of_range };
110+
return { first, std::errc::value_too_large };
111111
}
112112
}
113113
else
@@ -165,7 +165,7 @@ inline to_chars_result to_chars_nonfinite<__float128>(char* first, char* last, _
165165
else
166166
{
167167
// Avoid buffer overflow
168-
return { first, std::errc::result_out_of_range };
168+
return { first, std::errc::value_too_large };
169169
}
170170

171171
}
@@ -184,7 +184,7 @@ inline to_chars_result to_chars_nonfinite<__float128>(char* first, char* last, _
184184
else
185185
{
186186
// Avoid buffer overflow
187-
return { first, std::errc::result_out_of_range };
187+
return { first, std::errc::value_too_large };
188188
}
189189
}
190190
else
@@ -258,7 +258,7 @@ to_chars_result to_chars_hex(char* first, char* last, Real value, int precision)
258258

259259
if (buffer_size < real_precision || first > last)
260260
{
261-
return {last, std::errc::result_out_of_range};
261+
return {last, std::errc::value_too_large};
262262
}
263263

264264
// Extract the significand and the exponent
@@ -374,7 +374,7 @@ to_chars_result to_chars_hex(char* first, char* last, Real value, int precision)
374374
const std::ptrdiff_t total_length = total_buffer_length(real_precision, abs_unbiased_exponent, (value < 0));
375375
if (total_length > buffer_size)
376376
{
377-
return {last, std::errc::result_out_of_range};
377+
return {last, std::errc::value_too_large};
378378
}
379379

380380
// Round if required
@@ -483,7 +483,7 @@ to_chars_result to_chars_fixed_impl(char* first, char* last, Real value, chars_f
483483
auto real_precision = get_real_precision<Real>(precision);
484484
if (buffer_size < real_precision || first > last)
485485
{
486-
return {last, std::errc::result_out_of_range};
486+
return {last, std::errc::value_too_large};
487487
}
488488

489489
auto abs_value = std::abs(value);
@@ -534,7 +534,7 @@ to_chars_result to_chars_fixed_impl(char* first, char* last, Real value, chars_f
534534
const std::ptrdiff_t total_length = total_buffer_length(num_dig, value_struct.exponent, (value < 0));
535535
if (total_length > buffer_size)
536536
{
537-
return {last, std::errc::result_out_of_range};
537+
return {last, std::errc::value_too_large};
538538
}
539539

540540
auto r = to_chars_integer_impl(first, last, value_struct.significand);
@@ -598,7 +598,7 @@ to_chars_result to_chars_float_impl(char* first, char* last, Real value, chars_f
598598
// Sanity check our bounds
599599
if (first >= last)
600600
{
601-
return {last, std::errc::result_out_of_range};
601+
return {last, std::errc::value_too_large};
602602
}
603603

604604
auto abs_value = std::abs(value);

0 commit comments

Comments
 (0)