std::wstrin...ring_convert(3)
π NAME π
okay so this is std::wstring_convert::wstring_convert β and the NAME section literally says std::wstring_convert::wstring_convert - std::wstring_convert::wstring_convert, because it's that iconic and said it twice. bestie, we're in the C++ Standard Libary manual (yes, that spelling is staying exactly as the page has it), and the page header is literally std::wstrin...ring_convert(3). no cap, we're keeping the abbreviation. π
β¨ Synopsis β¨
here's the whole overload lineup, exactly as the page serves it:
wstring_convert() : wstring_convert( new Codecvt ) {}
(1)
explicit wstring_convert( Codecvt* pcvt );
(2)
wstring_convert( Codecvt* pcvt, state_type state );
(3)
explicit wstring_convert( const byte_string& byte_err,
const wide_string& wide_err =
wide_string() );
(4)
wstring_convert( const std::wstring_convert& ) = delete;
(5) (since C++14)
and what each one is giving:
- Default constructor.
- Constructs the
wstring_convertobject with a specified conversion facet, using default-constructed values for the shift state and the error strings. - Constructs the
wstring_convertobject with a specified conversion facet and specified shift state, using default-constructed values for the error strings. - Constructs the
wstring_convertobject with specified error strings, usingnew Codecvtas the conversion facet and the default-constructedstate_typeas shift state. - The copy constructor is deleted,
wstring_convertis notCopyConstructible.
πΈ Parameters πΈ
pcvtβ pointer to the conversion facet of typeCodecvt(behavior is undefined if this pointer is null) π¨stateβ initial value of the conversion shift statebyte_errβ narrow string to display on errorswide_errβ wide string to display on errors
π§ Defect reports π§
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
- DR
P0935R0β applied toC++11; behavior as published: default constructor wasexplicit; correct behavior: madeimplicitβ¨
π₯ Example π₯
the page has a lil // Run this code marker before the example, so here's the code, bestie:
#include <codecvt>
#include <locale>
#include <utility>
// utility wrapper to adapt locale-bound facets for wstring/wbuffer
convert
template<class Facet>
struct deletable_facet : Facet
{
using Facet::Facet; // inherit constructors
~deletable_facet() {}
};
int main()
{
// UTF-16le / UCS4 conversion
std::wstring_convert<
std::codecvt_utf16<char32_t, 0x10ffff, std::little_endian>
> u16to32;
// UTF-8 / wide string conversion with custom messages
std::wstring_convert<std::codecvt_utf8<wchar_t>> u8towide("Error!",
L"Error!");
// GB18030 / wide string conversion facet
typedef deletable_facet<std::codecvt_byname<wchar_t, char,
std::mbstate_t>> F;
std::wstring_convert<F> gbtowide(new F("zh_CN.gb18030"));
}
okay bestie that's the whole page π
source/version/date: http://cppreference.com Β· 2024.06.10 Β· page: std::wstrin...ring_convert(3) π«Ά
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms