arg_router  1.4.0
C++ command line argument parsing and routing
arg_router::utility::compile_time_optional< T > Class Template Reference

#include <arg_router/utility/compile_time_optional.hpp>

Public Types

using value_type = T
 

Public Member Functions

constexpr compile_time_optional (value_type val) noexcept
 
constexpr operator bool () const
 
constexpr const value_typeoperator-> () const noexcept
 
constexpr const value_typeoperator* () const noexcept
 
value_typeoperator-> () noexcept
 
value_typeoperator* () noexcept
 

Static Public Attributes

constexpr static bool empty = false
 

Detailed Description

template<typename T>
class arg_router::utility::compile_time_optional< T >

Compile-time equivalent of std::optional.

std::optional can be used in compile-time expressions, but not when used as a argument, this class can do that but comes with severe runtime limitations due to it.

An empty optional cannot be created and then populated later, nor cleared, as that state is a part of its template parameters (a void type is an empty compile_time_optional).

Like std::optional references cannot be stored internally, but it can use a std::reference_wrapper. Unlike std::optional this type has a specialisation that makes the std::reference_wrapper access transparent (i.e. you don't need to dereference twice).

Note
The std::reference_wrapper specialisation is not constexpr
Template Parameters
TValue type

Definition at line 29 of file compile_time_optional.hpp.

Member Typedef Documentation

◆ value_type

template<typename T >
using arg_router::utility::compile_time_optional< T >::value_type = T

Value type.

Definition at line 33 of file compile_time_optional.hpp.

Constructor & Destructor Documentation

◆ compile_time_optional()

template<typename T >
constexpr arg_router::utility::compile_time_optional< T >::compile_time_optional ( value_type  val)
inlineexplicitconstexprnoexcept

Constructor.

Parameters
valValue to copy into the optional

Definition at line 42 of file compile_time_optional.hpp.

Member Function Documentation

◆ operator bool()

template<typename T >
constexpr arg_router::utility::compile_time_optional< T >::operator bool ( ) const
inlineexplicitconstexpr

Implicit bool conversion operator.

Returns
True if not empty

Definition at line 48 of file compile_time_optional.hpp.

◆ operator*() [1/2]

template<typename T >
constexpr const value_type& arg_router::utility::compile_time_optional< T >::operator* ( ) const
inlineconstexprnoexcept

Dereference operator.

Note
Not available if empty
Returns
Reference

Definition at line 62 of file compile_time_optional.hpp.

◆ operator*() [2/2]

template<typename T >
value_type& arg_router::utility::compile_time_optional< T >::operator* ( )
inlinenoexcept

Non-const overload.

Note
Not available if empty
Returns
Reference

Definition at line 76 of file compile_time_optional.hpp.

◆ operator->() [1/2]

template<typename T >
constexpr const value_type* arg_router::utility::compile_time_optional< T >::operator-> ( ) const
inlineconstexprnoexcept

Dereference to member operator.

Note
Not available if empty
Returns
Pointer

Definition at line 55 of file compile_time_optional.hpp.

◆ operator->() [2/2]

template<typename T >
value_type* arg_router::utility::compile_time_optional< T >::operator-> ( )
inlinenoexcept

Non-const overload.

Note
Not available if empty
Returns
Pointer

Definition at line 69 of file compile_time_optional.hpp.

Member Data Documentation

◆ empty

template<typename T >
constexpr static bool arg_router::utility::compile_time_optional< T >::empty = false
staticconstexpr

True if empty.

Definition at line 36 of file compile_time_optional.hpp.


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