sparrow 0.9.0
Loading...
Searching...
No Matches
sparrow::nullable_variant< T > Class Template Reference

Variant of nullable types with has_value() convenience method. More...

#include <nullable.hpp>

Inheritance diagram for sparrow::nullable_variant< T >:
[legend]
Collaboration diagram for sparrow::nullable_variant< T >:
[legend]

Public Types

using base_type = std::variant<T...>
 

Public Member Functions

constexpr nullable_variant (const nullable_variant &)=default
 
constexpr nullable_variant (nullable_variant &&) noexcept=default
 
constexpr nullable_variantoperator= (const nullable_variant &)
 Copy assignment operator.
 
constexpr nullable_variantoperator= (nullable_variant &&) noexcept
 Move assignment operator.
 
constexpr operator bool () const
 Conversion to bool indicating non-null state.
 
constexpr bool has_value () const
 Checks whether the active alternative contains a valid value.
 

Detailed Description

template<class... T>
requires (sizeof...(T) > 0 && (is_nullable_v<T> && ...))
class sparrow::nullable_variant< T >

Variant of nullable types with has_value() convenience method.

This class extends std::variant to work specifically with nullable types, providing a uniform has_value() interface across all alternative types.

Template Parameters
TPack of nullable types that can be stored in the variant
Precondition
All types in T must be nullable types
sizeof...(T) must be > 0
Postcondition
Provides has_value() that works regardless of active alternative
Maintains all std::variant functionality
Examples
/home/runner/work/sparrow/sparrow/include/sparrow/utils/nullable.hpp.

Definition at line 1075 of file nullable.hpp.

Member Typedef Documentation

◆ base_type

template<class... T>
using sparrow::nullable_variant< T >::base_type = std::variant<T...>

Constructor & Destructor Documentation

◆ nullable_variant() [1/2]

template<class... T>
sparrow::nullable_variant< T >::nullable_variant ( const nullable_variant< T > & )
constexprdefault
Examples
/home/runner/work/sparrow/sparrow/include/sparrow/utils/nullable.hpp.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ nullable_variant() [2/2]

template<class... T>
sparrow::nullable_variant< T >::nullable_variant ( nullable_variant< T > && )
constexprdefaultnoexcept
Here is the call graph for this function:

Member Function Documentation

◆ has_value()

template<class... T>
requires (sizeof...(T) > 0 && (is_nullable_v<T> && ...))
bool sparrow::nullable_variant< T >::has_value ( ) const
constexpr

Checks whether the active alternative contains a valid value.

Returns
true if active alternative is non-null, false otherwise
Postcondition
Calls has_value() on the active nullable alternative
Examples
/home/runner/work/sparrow/sparrow/include/sparrow/utils/nullable.hpp.

Definition at line 1408 of file nullable.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator bool()

template<class... T>
requires (sizeof...(T) > 0 && (is_nullable_v<T> && ...))
sparrow::nullable_variant< T >::operator bool ( ) const
explicitconstexpr

Conversion to bool indicating non-null state.

Returns
true if active alternative has a valid value
Postcondition
Return value equals has_value()

Definition at line 1401 of file nullable.hpp.

Here is the call graph for this function:

◆ operator=() [1/2]

template<class... T>
requires (sizeof...(T) > 0 && (is_nullable_v<T> && ...))
nullable_variant< T... > & sparrow::nullable_variant< T >::operator= ( const nullable_variant< T > & rhs)
constexpr

Copy assignment operator.

Parameters
rhsSource variant to copy from
Returns
Reference to this variant
Postcondition
This variant contains a copy of rhs
Active alternative matches rhs
Examples
/home/runner/work/sparrow/sparrow/include/sparrow/utils/nullable.hpp.

Definition at line 1385 of file nullable.hpp.

Here is the call graph for this function:

◆ operator=() [2/2]

template<class... T>
requires (sizeof...(T) > 0 && (is_nullable_v<T> && ...))
nullable_variant< T... > & sparrow::nullable_variant< T >::operator= ( nullable_variant< T > && rhs)
constexprnoexcept

Move assignment operator.

Parameters
rhsSource variant to move from
Returns
Reference to this variant
Postcondition
This variant contains moved content from rhs
rhs is left in valid but unspecified state

Definition at line 1393 of file nullable.hpp.

Here is the call graph for this function:

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