Optional-like lightweight wrapper around type T with no space overhead. More...
#include <kanzi/core/util/flat_optional.hpp>
Public Types | |
| using | ValueType |
| Alias for underlying type. | |
Public Member Functions | |
| KZ_NO_DISCARD optional< T > | createOptional () const noexcept |
| Creates a kanzi::optional copy of the stored value. | |
| FlatOptional () noexcept | |
| Constructor. | |
| template<typename U , typename = enable_if_t<is_convertible_v<decay_t<U>, T>>> | |
| FlatOptional (U &&value) noexcept | |
| Constructor. | |
| KZ_NO_DISCARD bool | hasValue () const noexcept |
| Checks if a value is stored. | |
| KZ_NO_DISCARD | operator bool () const noexcept |
| Conversion operator to bool. | |
| KZ_NO_DISCARD T && | operator* () &&noexcept |
| Provides access to stored value via rvalue reference. | |
| KZ_NO_DISCARD T & | operator* () &noexcept |
| Provides access to stored value via reference. | |
| KZ_NO_DISCARD const T && | operator* () const &&noexcept |
| Provides access to stored value via const rvalue reference. | |
| KZ_NO_DISCARD const T & | operator* () const &noexcept |
| Provides access to stored value via const reference. | |
| KZ_NO_DISCARD const T * | operator-> () const noexcept |
| Provides access to stored value via const pointer. | |
| KZ_NO_DISCARD T * | operator-> () noexcept |
| Provides access to stored value via pointer. | |
| void | reset () noexcept |
| Replaces stored value with sentinel value. | |
| template<typename U , typename = enable_if_t<is_convertible_v<decay_t<U>, T>>> | |
| void | reset (U &&newValue) noexcept |
| Stores a new value inside. | |
| void | swap (FlatOptional &other) |
| Swap function. | |
| KZ_NO_DISCARD optional< T > | toOptional () &&noexcept |
| Converts FlatOptional to kanzi::optional. | |
Static Public Member Functions | |
| static constexpr T | getSentinel () noexcept |
| Gets sentinel value that can be used to represent an empty state. | |
Protected Attributes | |
| T | m_value |
| Stored value. | |
Optional-like lightweight wrapper around type T with no space overhead.
Uses sentinel value to represent empty state.
| T | Type of the value. |
| sentinel | Sentinel value that can be used to represent empty state. |
| using kanzi::FlatOptional< T, sentinel, typename >::ValueType |
Alias for underlying type.
|
inlineexplicitnoexcept |
Constructor.
Creates FlatOptional with empty state.
|
inlineexplicitnoexcept |
Constructor.
| U | Deduced type for universal reference of T. |
| value | Value to store. |
|
inline |
Swap function.
| other | Second object to swap with. |
|
inlinenoexcept |
Provides access to stored value via reference.
|
inlinenoexcept |
Provides access to stored value via const reference.
|
inlinenoexcept |
Provides access to stored value via rvalue reference.
|
inlinenoexcept |
Provides access to stored value via const rvalue reference.
|
inlinenoexcept |
Provides access to stored value via pointer.
|
inlinenoexcept |
Provides access to stored value via const pointer.
|
inlineexplicitnoexcept |
Conversion operator to bool.
|
inlinenoexcept |
Checks if a value is stored.
|
inlinestaticconstexprnoexcept |
Gets sentinel value that can be used to represent an empty state.
|
inlinenoexcept |
Replaces stored value with sentinel value.
Stores a new value inside.
| U | Deduced type for universal reference of T. |
| newValue | New value to store. |
|
inlinenoexcept |
Converts FlatOptional to kanzi::optional.
Use by moving the value first:
| nullopt | FlatOptional represented an empty value. |
|
inlinenoexcept |
Creates a kanzi::optional copy of the stored value.
| nullopt | FlatOptional represented an empty value. |
|
protected |
Stored value.