AnCH Framework 0.2
Another C++ Hack: C++23 utility libraries
Loading...
Searching...
No Matches
anch::Optional< T > Class Template Reference

std::optional usefull methods. More...

#include <optional.hpp>

Inheritance diagram for anch::Optional< T >:
Collaboration diagram for anch::Optional< T >:

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

Detailed Description

template<typename T>
class anch::Optional< T >

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.

Since
0.1
Author
Vincent Lachenal

Constructor & Destructor Documentation

◆ Optional() [1/2]

template<typename T>
anch::Optional< T >::Optional ( const std::optional< T > & other)
constexpr

Optional constructor from std::optional copy

Parameters
otherthe std::optional to copy

◆ Optional() [2/2]

template<typename T>
anch::Optional< T >::Optional ( std::optional< T > && other) const
constexprnoexcept

Optional constructor from std::optional move

Parameters
otherthe std::optional to move

Member Function Documentation

◆ ifValue()

template<typename T>
void anch::Optional< T >::ifValue ( std::function< void(const T &)> func) const

Apply treatment if optional has value

Parameters
functhe treatment to apply when optional has value

◆ ifValueOrElse()

template<typename T>
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

Parameters
functhe treatment to apply when optional has value
fallbackthe treatment to apply when optional has no value

◆ map()

template<typename T>
template<typename U>
Optional< U > anch::Optional< T >::map ( std::function< U(const T &)> mapper) const

Map optional value into another type

Parameters
mapperthe mapping function
Returns
the mapped value when optional has value, an empty optional otherwise
Here is the call graph for this function:

The documentation for this class was generated from the following file: