std::optional usefull methods.
More...
#include <optional.hpp>
Public Member Functions | |
| constexpr | Optional (const std::optional< T > &other) |
| constexpr | Optional (std::optional< T > &&other) noexcept(std::is_nothrow_move_constructible_v< T >) |
| void | ifValue (std::function< void(const T &)> func) const |
| void | ifValueOrElse (std::function< void(const T &)> func, std::function< void()> fallback) const |
| template<typename U> | |
| Optional< U > | map (std::function< U(const T &)> mapper) const |
std::optional usefull methods.
Provides some missing (from my point of view) features to std::optional .
Every std::optional constructor and method is available. Assignments use these constructors.
Since C++23, std::optional provides transform , and_then and or_else which cover map and ifValueOrElse use cases.
|
constexpr |
Optional constructor from std::optional copy
| other | the std::optional to copy |
|
constexprnoexcept |
Optional constructor from std::optional move
| other | the std::optional to move |
| void anch::Optional< T >::ifValue | ( | std::function< void(const T &)> | func | ) | const |
Apply treatment if optional has value
| func | the treatment to apply when optional has value |
| void anch::Optional< T >::ifValueOrElse | ( | std::function< void(const T &)> | func, |
| std::function< void()> | fallback ) const |
Apply treatment if optional has value or apply fallback treatment
| func | the treatment to apply when optional has value |
| fallback | the treatment to apply when optional has no value |
| Optional< U > anch::Optional< T >::map | ( | std::function< U(const T &)> | mapper | ) | const |
Map optional value into another type
| mapper | the mapping function |