std::bad_optional_access(3)

πŸ“¦
version 2024.07.05 Β· 4 versions
, in nixpkgs unstable, opensuse-leap 16.0

πŸ’– std::bad_optional_access(3) πŸ’–

okay so bestie, this is the std::bad_optional_access(3) page from the C++ Standard Libary manual β€” yes, that's the manual name, we're keeping it exactly πŸ’…. Buckle up, it's exception-lore time.

✨ NAME ✨

std::bad_optional_access β€” std::bad_optional_access. That's the whole NAME section, bestie, it's giving "my name is my name" main character energy πŸŽ€.

🌸 Synopsis 🌸

Defined in header <optional>
class bad_optional_access;    (since C++17)

It defines a type of object to be thrown by std::optional::value when accessing an optional object that does not contain a value. That's the whole point, no cap ✨.

Inheritance diagram vibes: the asset is std-bad optional access-inheritance-lwg2806.svg πŸ¦‹.

🌈 Member functions 🌈

  • constructor β€” constructs a new bad_optional_access object (public member function)
  • operator= β€” replaces the bad_optional_access object (public member function)
  • what β€” returns the explanatory string (public member function)

πŸ“ std::bad_optional_access::bad_optional_access πŸ“

bad_optional_access() noexcept;                                   (1)
(since C++17)
bad_optional_access( const bad_optional_access& other ) noexcept; (2)
(since C++17)

Constructs a new bad_optional_access object with an implementation-defined null-terminated byte string which is accessible through what(). slay πŸ’….

  1. Default constructor.
  2. Copy constructor. If *this and other both have dynamic type std::bad_optional_access then std::strcmp(what(), other.what()) == 0.

🌸 Parameters 🌸

  • other β€” another exception object to copy

πŸ’… std::bad_optional_access::operator= πŸ’…

bad_optional_access& operator=( const bad_optional_access& other )
(since C++17)
noexcept;

Assigns the contents with those of other. If *this and other both have dynamic type std::bad_optional_access then std::strcmp(what(), other.what()) == 0 after assignment. iconic behavior, honestly πŸ‘‘.

πŸŽ€ Parameters πŸŽ€

  • other β€” another exception object to assign with

⭐ Return value ⭐

*this

πŸ¦‹ std::bad_optional_access::what πŸ¦‹

virtual const char* what() const noexcept;  (since C++17)

Returns the explanatory string. periodt πŸ’œ.

🌈 Parameters 🌈

(none)

✨ Return value ✨

Pointer to a null-terminated string with explanatory information. The string is suitable for conversion and display as a std::wstring. The pointer is guaranteed to be valid at least until the exception object from which it is obtained is destroyed, or until a non-const member function (e.g. copy assignment operator) on the exception object is called. very "handle with care" of it all 🫢.

πŸ’€ Notes πŸ’€

Implementations are allowed but not required to override what().

πŸ‘‘ Inherited from std::exception πŸ‘‘

🌸 Member functions 🌸

  • destructor β€” destroys the exception object [virtual] (virtual public member function of std::exception)
  • what β€” returns an explanatory string [virtual] (virtual public member function of std::exception)

source/version + date sign-off tea: http://cppreference.com, 2024.06.10, page std::bad_optional_access(3). mwah πŸ’‹πŸ«Ά

πŸ“¦ where this page comes from