Wrapper class around a type with the capability to both store the type of default and its value, if any exists.
This class has 3 valid states:
| State | type_ | value_ |
|---|---|---|
| Required key | DefaultType::Null | std::nullopt |
| Default value | DefaultType::Value | ≠ std::nullopt |
| Key with dependent default | DefaultType::Dependent | std::nullopt |
There is a constructor for each of the cases above.
| T | The default value type. |
Key class and it is meant to be rigid in its usage. E.g., the constructor specifying a DefaultType is meant to only accept DefaultType::Dependent because this is the only way we want it to be used. Public Member Functions | |
| Default () | |
Construct a new Default object which denotes a mandatory value without a default. More... | |
| Default (T in) | |
Construct a new Default object storing its default value. More... | |
| Default (DefaultType type) | |
Construct a new Default object which has a value dependent on external information. More... | |
| T | value () const |
| Retrieve the default value stored in the object. More... | |
| bool | is_dependent () const noexcept |
| Ask whether the default value depends on other external information. More... | |
Private Attributes | |
| DefaultType | type_ = DefaultType::Value |
| The type of default value. More... | |
| std::optional< T > | value_ = std::nullopt |
| The default value, if any. More... | |
Friends | |
| class | Key< T > |
|
inline |
|
inlineexplicit |
|
inlineexplicit |
Construct a new Default object which has a value dependent on external information.
| type | The type of default (it should be DefaultType::Dependent ). |
| std::logic_error | if called with a type different from DefaultType::Dependent . |
Definition at line 344 of file key.h.
|
inline |
|
inlinenoexcept |
Ask whether the default value depends on other external information.
true if this is the case, false if the default value is known or none exists.
|
private |
|
private |