AUI Framework  master
Cross-platform module-based framework for developing C++20 desktop applications
AOptional< T > Class Template Reference

Utility wrapper implementing the stack-allocated (fast) optional idiom. More...

Detailed Description

template<typename T>
class AOptional< T >

Utility wrapper implementing the stack-allocated (fast) optional idiom.

Examples
/github/workspace/aui.views/src/AUI/View/AView.h.

Public Member Functions

constexpr AOptional (std::nullopt_t) noexcept
 
template<typename U = T, std::enable_if_t< std::is_constructible_v< T, U > &&std::is_convertible_v< U &&, T >, bool > = true>
constexpr AOptional (U &&rhs) noexcept
 
template<typename U = T, std::enable_if_t< std::is_constructible_v< T, U > &&!std::is_convertible_v< U &&, T >, bool > = true>
constexpr AOptional (U &&rhs) noexcept
 
constexpr AOptional (const AOptional &rhs)
 
constexpr AOptional (AOptional &&rhs) noexcept
 
template<typename U >
constexpr AOptional (const AOptional< U > &rhs)
 
template<typename U >
constexpr AOptional (AOptional< U > &&rhs) noexcept
 
bool hasValue () const noexcept
 
constexpr operator bool () const noexcept
 
template<typename... Args>
constexpr AOptional< T > & emplace (Args &&... args)
 
constexpr AOptional< T > & operator= (std::nullopt_t) noexcept
 
template<typename U = T, typename std::enable_if_t< std::is_convertible_v< U &&, T >, bool > = true>
constexpr AOptional< T > & operator= (U &&rhs) noexcept
 
constexpr AOptional< T > & operator= (const AOptional &rhs) noexcept
 
constexpr AOptional< T > & operator= (AOptional &&rhs) noexcept
 
template<typename U >
constexpr AOptional< T > & operator= (const AOptional< U > &rhs) noexcept
 
template<typename U >
constexpr AOptional< T > & operator= (AOptional< U > &&rhs) noexcept
 
template<typename U = T>
constexpr AOptional< T > & operator= (T &&rhs) noexcept
 
T & value () noexcept
 
const T & value () const noexcept
 
T * ptr () noexcept
 
const T * ptr () const noexcept
 
T * operator-> () noexcept
 
const T * operator-> () const noexcept
 
T & operator* () noexcept
 
const T & operator* () const noexcept
 
void reset () noexcept
 
T & valueOrException (const char *message="empty optional")
 value or exception
 
const T & valueOrException (const char *message="empty optional") const
 value or exception
 
template<typename F >
valueOr (F &&alternative) const
 value or alternative (either value or callback) More...
 
template<typename U >
bool operator== (const AOptional< U > &rhs) const noexcept
 
template<typename U >
bool operator== (const U &rhs) const noexcept
 
bool operator== (const std::nullopt_t &rhs) const noexcept
 
template<aui::invocable< const T & > Mapper>
auto map (Mapper &&mapper) -> AOptional< decltype(std::invoke(std::forward< Mapper >(mapper), value()))> const
 If a value is present, apply the provided mapper function to it. More...
 

Member Function Documentation

◆ map()

template<typename T >
template<aui::invocable< const T & > Mapper>
auto AOptional< T >::map ( Mapper &&  mapper) -> AOptional<decltype(std::invoke(std::forward<Mapper>(mapper), value()))> const
inline

If a value is present, apply the provided mapper function to it.

Parameters
mappermapper function to apply. The mapper is invoked as a STL projection (i.e., the mapper could be lambda, pointer-to-member function or field).

◆ valueOr()

template<typename T >
template<typename F >
T AOptional< T >::valueOr ( F &&  alternative) const
inline

value or alternative (either value or callback)

Template Parameters
Fsame as T or invocable returning T or invokable throwing a exception
Parameters
alternative
Returns

#include <AUI/Common/AOptional.h>


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