std::ctype::~ctype(3)

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

🌸 std::ctype::~ctype(3) 🌸

okay bestie, this is the C++ Standard Libary manual page for std::ctype::~ctype β€” yes, the destructor episode, the goodbye era of a std::ctype facet. πŸ’…

✨ NAME ✨

std::ctype::~ctype - std::ctype::~ctype

🧚 Synopsis 🧚

Defined in header <locale>:

protected: ~ctype();

It destructs a std::ctype facet. Literally its whole job. 🫢

This destructor is protected and virtual (due to the base class destructor being virtual). An object of type std::ctype, like most facets, can only be destroyed when the last std::locale object that implements this facet goes out of scope or if a user-defined class is derived from std::ctype and implements a public destructor. No cap. πŸ’…

πŸŽ€ Example πŸŽ€

// Run this code

#include <iostream>
#include <locale>

struct Destructible_ctype : public std::ctype<wchar_t>
{
    Destructible_ctype(std::size_t refs = 0) : ctype(refs) {}
    // note: the implicit destructor is public
};

int main()
{
    Destructible_ctype dc;
    // std::ctype<wchar_t> c; // compile error: protected destructor
}

Peep that commented-out line, bestie: std::ctype<wchar_t> c; is a compile error because the destructor is protected. The derived Destructible_ctype is giving β€œI made the destructor public” main character energy. 😭✨


mwah πŸ’‹ β€” sourced from cppreference.com, version/date 2024.06.10, and that’s the whole std::ctype::~ctype(3) page, periodt. 🫢

πŸ“¦ where this page comes from