Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

std::from_chars overload for wchar_t?

Is there any reason why std::from_chars doesn't have an overload for wchar_t?

Currently, there are only four overloads one of them being:

constexpr std::from_chars_result from_chars( const char* first, const char* last,
                                             /*see below*/& value, int base = 10 );

So what is the reason that there doesn't exist any overload for wchar_t or other character types? Is there any chance that they will be added in C++26? If not then are there equivalents for wchar_t?

like image 829
digito_evo Avatar asked Oct 18 '25 09:10

digito_evo


1 Answers

The from/to_chars series of functions are for elementary string conversions. These are the most elemental of numeric conversions. As such, they only support the most basic encoding: your system's native narrow character set (usually Unicode codepoints less than 128 encoded as UTF-8 or ASCII).

If you have text in some other encoding, it is on yourself to convert that encoding from/to the system narrow encoding in order to use these functions.

The expected use cases for these strings are for things like writing to/reading from textual formats like JSON. Such files are almost universally UTF-8 encoded (or ASCII), and when they call for numbers, their numbers are both locale-independent (always using . for the radix mark, for example) and encodes numbers using only the ASCII-part of Unicode.

like image 192
Nicol Bolas Avatar answered Oct 19 '25 22:10

Nicol Bolas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!