std::wstrin...ing_convert(3)
πΈ NAME πΈ
okay so bestie, this is the manual page for std::wstring_convert::~wstring_convert π
β that's the destructor of std::wstring_convert, straight out of the C++ Standard Library, and honestly it's giving "one-line wonder, but with lore" β¨ (the page title literally just repeats std::wstring_convert::~wstring_convert, iykyk).
π Synopsis π
~wstring_convert();
so like, no arguments, no return value β it just does its one job: it destroys the wstring_convert object and deletes the pointer to the conversion facet π«Ά. that's it. that's the whole vibe check. iconic, honestly.
π Notes π
okay here's where it gets spicy πΆοΈ β implementations are not all built the same, and you need to know this:
- some implementations are able to delete any facet, including the locale-specific facets with protected destructors π
- other implementations require the facet to have a public destructor, similar to the locale-independent facets from
<codecvt>π
this whole situation is LWG issue 721 β write that down, bestie π
π¦ Example π¦
// Run this code πββοΈβ¨
#include <codecvt>
#include <locale>
#include <utility>
// utility wrapper to adapt locale-bound facets for wstring/wbuffer
convert
template<class Facet>
struct deletable_facet : Facet
{
template<class ...Args>
deletable_facet(Args&& ...args) :
Facet(std::forward<Args>(args)...) {}
~deletable_facet() {}
};
int main()
{
// GB18030 / UCS4 conversion, using locale-based facet directly
// typedef std::codecvt_byname<char32_t, char, std::mbstate_t>
gbfacet_t;
// Compiler error: "calling a protected destructor of
// codecvt_byname<> in ~wstring_convert"
// std::wstring_convert<gbfacet_t> gbto32(new
gbfacet_t("zh_CN.gb18030"));
// GB18030 / UCS4 conversion facet using a facet with public
destructor
typedef deletable_facet<std::codecvt_byname<char32_t, char,
std::mbstate_t>> gbfacet_t;
std::wstring_convert<gbfacet_t> gbto32(new
gbfacet_t("zh_CN.gb18030"));
} // destructor called here
so what's the tea β: the deletable_facet struct is your little utility wrapper that adapts locale-bound facets for wstring/wbuffer convert, giving them a public ~deletable_facet() {} so the destructor actually works π. the commented-out typedef std::codecvt_byname<char32_t, char, std::mbstate_t> gbfacet_t; block straight-up does not compile β you get a compiler error, calling a protected destructor of codecvt_byname<> in ~wstring_convert π β because you tried to use the locale-based facet directly. the uncommented version routes through deletable_facet and happily does GB18030 / UCS4 conversion. and yeah, } // destructor called here β the destructor gets called right there at the closing brace ππ«Ά
π SEE ALSO π
ngl there's nothing extra listed on this page, bestie β this one's a short king π
also a lil warning for you: because of the implementation differences up in Notes, whether your facet's destructor is public or protected genuinely changes whether this compiles. don't come for me, come for LWG issue 721 β¨
mwah π β that's the whole page, brought to you by cppreference.com, dated 2024.06.10, and filed under std::wstrin...ing_convert(3) in the C++ Standard Libary (yes that's how the header spells it, no I will not be fixing it, slay ππ)
π¦ 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