std::bad_optional_access(3)
π 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_accessobject (public member function) operator=β replaces thebad_optional_accessobject (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 π
.
- Default constructor.
- Copy constructor. If
*thisandotherboth have dynamic typestd::bad_optional_accessthenstd::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 ofstd::exception) - what β returns an explanatory string
[virtual](virtual public member function ofstd::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
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms