liveBook · Manning

Value

As explained in Learn C++ by Example

value is an optional member function that accesses the contained object and throws when no value is present.

value() retrieves the object stored in a std::optional. Check whether the optional contains a value first; calling value() when it is empty throws an exception. section 3.1.2

Reading a guess

A number-guessing loop uses read_number to return an optional integer. After the loop confirms a guess exists, guess.value() retrieves it for comparison or output; an empty optional lets the player give up. section 3.1.2

How Learn C++ by Example covers it

How deep it goes
Defines retrieval and empty-state failure, but leaves exception handling unspecified.
Examples
Uses a number-guessing game where optional input supplies guesses or signals that the player wants to stop.
What it assumes
Assumes optional presence checks and introduces optional values through numeric stream input.
What you can do after
Apply it via std::optional::value to retrieve a contained value after confirming presence.
How it connects
Connects std::optional with explicit operator bool, optional input, streams, and exceptions.

This explainer was generated by Manning's knowledge graph from the text of Learn C++ by Example. The section links point to the parts of the book it draws on.