According to the C++ standard (§30.7.5.2.4 of C++17 draft (N4659)), out << ch
will not perform a widening operation on ch
, if ch
is a char
and out
is a std::ostream
.
Does this imply that std::ctype<char>::widen()
(i.e., char
-> char
) is guaranteed by the standard to be an identity function (widen(ch) == ch
) for all characters in the basic source character set?
If so, does this, in turn, imply that all locales are required by the standard to use the same non-wide (or multi-byte) encoding of characters from the basic source character set?
If not, it seems like out << 'x'
, with a particular choice of character encoding for literals, might not work in all locales, even when it works in some. That is, there might be no choice of character literal encoding, such that out << 'x'
works in all locales simultaneously.
No, it just says that in the case of
template<class traits>
basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>& out, char c);
where both the stream and the <<
operator trades in the same char
type there is no conversion.
If
c
has typechar
and the character type of the stream is notchar
, then seq consists ofout.widen(c)
; otherwise seq consists ofc
.
In all other cases the locale is used to optionally transform the character with no restrictions on what the locales might do.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With