std::optional::~optional(3)

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

πŸ’… std::optional::~optional(3) πŸ’…

okay bestie, this is the std::optional::~optional(3) page from the C++ Standard Libary manual β€” yes, that's the manual name right there, folded in at the top like a lil name tag 🫢.


πŸŽ€ NAME πŸŽ€

std::optional::~optional β€” the manual's description is literally just std::optional::~optional again, so it's giving "I am my own summary" energy πŸ’….


✨ Synopsis ✨

Here's the signature, exactly, no edits:

~optional();  (since C++17)
              (constexpr since C++20)

That's the whole synopsis, and the since C++17 / constexpr since C++20 notes are right there in it β€” keep those eras in mind πŸŽ€.


πŸ’… Notes πŸ’…

If the object contains a value and the type T is not trivially destructible (see std::is_trivially_destructible), it destroys the contained value by calling its destructor, as if by value().T::~T().

Otherwise, it does nothing. literally nothing, iconically 😭.

If T is trivially-destructible, then this destructor is also trivial, so std::optional<T> is also trivially-destructible. slay ✨.

🫢 Defect reports 🫢

The following behavior-changing defect reports were applied retroactively to previously published C++ standards:

  • DR: P2231R1
    • Applied to: C++20
    • Behavior as published: the destructor was not constexpr while non-trivial destructors can be constexpr in C++20
    • Correct behavior: made constexpr

periodt, that's the whole receipt πŸ’….


and that's the page! source/version: http://cppreference.com Β· date: 2024.06.10 β€” byeee, drink water and stan trivial destructors responsibly πŸ’–πŸŒΈ

πŸ“¦ where this page comes from