std::time_get::~time_get(3)

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

πŸ’– NAME πŸ’–

std::time_get::~time_get β€” literally std::time_get::~time_get, bestie. This is the destructor page from the C++ Standard Libary manual, and it’s giving β€œtiny but important facet cleanup” energy. πŸ’…

✨ Synopsis ✨

Defined in header <locale>:

protected: ~time_get();

Okay so this destructs a std::time_get facet. It’s protected and virtual (due to the base class destructor being virtual). And because of that protected-ness, an object of type std::time_get, 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::time_get and implements a public destructor. No cap, that’s the whole vibe. πŸ¦‹

Heads up: the destructor is protected, so that last part is the loophole the example is using β€” a derived class with a public destructor. πŸ”₯

🌸 Example 🌸

// Run this code

#include <iostream>
#include <locale>

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

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

Look at that little Destructible_time_get slaying with a public implicit destructor, while std::time_get<wchar_t> c; gets dunked on by a compile error because the destructor is protected. Iconic. 😭


Source/version check: this page comes from http://cppreference.com, dated 2024.06.10, with the manual tag std::time_get::~time_get(3). Bye bestie, go destroy your facets responsibly! 🫢✨

πŸ“¦ where this page comes from