26#if GCONFIG_HAVE_CXX_OPTIONAL
37 template <
typename T>
class optional ;
64 explicit operator
bool() const noexcept ;
84 void doThrow() const ;
88 bool m_has_value {
false} ;
105 m_has_value = false ;
123 if( !m_has_value ) doThrow() ;
130 throw std::runtime_error(
"bad optional access" ) ;
136 return m_has_value ? m_value : default_ ;
A class template like a simplified c++17 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.
void reset()
Clears the value.
T value_or(const T &) const
Returns the value or a default.