std::wbuffe...fer_convert(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

NAME πŸ¦‹

okay so bestie, this is the std::wbuffer_convert::~wbuffer_convert page from the C++ Standard Libary manual (yes, that’s the header’s spelling, and we love her anyway 😭), and it’s literally the destructor for std::wbuffer_convert. cleanup icon behavior only πŸ’…βœ¨


Synopsis πŸ’–

the signature is babygirl tiny. it lives in the header <locale>:

          Defined in header <locale>
          ~wbuffer_convert();

so ~wbuffer_convert(); is the destructor, and its whole job is: destroys the wbuffer_convert object and deletes the pointer to the conversion facet. periodt 🫢


Notes 🌸

okay so here’s the implementation tea, no cap: 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>. that distinction is literally the whole note, bestie πŸ§šπŸ’œ


Example πŸŽ€

this example is code, so i’m keeping it exactly as it is. run this code, bestie:

       // Run this code

        #include <codecvt>
        #include <iostream>
        #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 ~wbuffer_convert"
        //  std::wbuffer_convert<gbfacet_t, char32_t>
        //      gbto32(std::cout.rdbuf(), 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::wbuffer_convert<gbfacet_t, char32_t>
                gbto32(std::cout.rdbuf(), new gbfacet_t("zh_CN.gb18030"));
        } // destructor called here

the comment at the end says the destructor is called here, and the wrapper is there to adapt locale-bound facets for wstring/wbuffer convert. iykyk πŸ’»πŸ’–


See also πŸ”₯

  • destructor β€” destructs the wstring_convert and its conversion facet; it’s a public member function of std::wstring_convert<Codecvt,Elem,Wide_alloc,Byte_alloc>.

byeee bestie πŸ«ΆπŸ’‹ β€” this page’s source/version is http://cppreference.com, dated 2024.06.10. that’s the footer tea, and she’s cute. no cap πŸ’…βœ¨

πŸ“¦ where this page comes from