AnCH Framework 0.1
Another C++ Hack Framework
 
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 () noexcept
 
constexpr Optional (std::nullopt_t null) noexcept
 
constexpr Optional (const std::optional< T > &other)
 
constexpr Optional (std::optional< T > &&other) noexcept
 
template<typename U>
 Optional (const std::optional< U > &other)
 
template<typename U>
 Optional (std::optional< U > &&other)
 
template<typename... Args>
constexpr Optional (std::in_place_t inplace, Args &&... args)
 
template<typename U, typename... Args>
constexpr Optional (std::in_place_t inplace, std::initializer_list< U > ilist, Args &&... args)
 
template<typename U = T>
constexpr Optional (U &&value)
 
virtual ~Optional ()
 
void ifValue (std::function< void(const T &)> func)
 
void ifValueOrElse (std::function< void(const T &)> func, std::function< void()> fallback)
 
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 .

Since
0.1
Author
Vincent Lachenal

Constructor & Destructor Documentation

◆ Optional() [1/9]

template<typename T>
anch::Optional< T >::Optional ( )
constexprnoexcept

Optional default constructor

◆ Optional() [2/9]

template<typename T>
anch::Optional< T >::Optional ( std::nullopt_t null)
constexprnoexcept

Optional constructor

Parameters
nullthe NULL value

◆ Optional() [3/9]

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

Optional 'copy' construtor

Parameters
otherthe std::optional to copy

◆ Optional() [4/9]

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

Optional 'move' constructor

Parameters
otherthe std::optional to move

◆ Optional() [5/9]

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

Optional converting 'copy' construtor

Parameters
otherthe std::optional to copy

◆ Optional() [6/9]

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

Optional converting 'move' constructor

Parameters
otherthe std::optional to move

◆ Optional() [7/9]

template<typename T>
template<typename... Args>
anch::Optional< T >::Optional ( std::in_place_t inplace,
Args &&... args )
explicitconstexpr

Optional constructor.
This constructor will initialize containing object with args.

Parameters
inplaceparameters to force T construction
argsthe T type constructor arguments

◆ Optional() [8/9]

template<typename T>
template<typename U, typename... Args>
anch::Optional< T >::Optional ( std::in_place_t inplace,
std::initializer_list< U > ilist,
Args &&... args )
explicitconstexpr

Optional constructor.
This constructor will initialize containing object with args.

Parameters
inplaceparameters to force T construction
ilistthe std::list initializer
argsthe T type constructor arguments

◆ Optional() [9/9]

template<typename T>
template<typename U>
anch::Optional< T >::Optional ( U && value)
constexpr

Optional constructor.

Parameters
valuethe value to convert

◆ ~Optional()

template<typename T>
anch::Optional< T >::~Optional ( )
virtual

Optional destructor

Member Function Documentation

◆ ifValue()

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

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 )
inline

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
inline

Transform optional type to another.
It value is not set, return an empty optional.

Parameters
mapperthe mapping function
Returns
the new optional
+ Here is the call graph for this function:

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