30 template <
typename T>
class optional ;
55 explicit operator
bool() const noexcept ;
75 void doThrow() const ;
79 bool m_has_value {
false} ;
96 m_has_value(has_value)
103 m_has_value = false ;
121 if( !m_has_value ) doThrow() ;
128 throw std::runtime_error(
"bad optional access" ) ;
134 return m_has_value ? m_value : default_ ;
A class template like a simplified c++17 std::optional.
void clear()
Clears the value. Not in std::optional.
optional() noexcept(noexcept(T()))
Default constructor for no value.
optional< T > & operator=(const T &)
Assignment for a defined value.
const T & value() const
Returns the value.
bool has_value() const noexcept
Returns true if a defined value.
T value_or(const T &) const
Returns the value or a default.