sparrow 0.9.0
Loading...
Searching...
No Matches
sparrow::nullable< T, B > Class Template Reference

#include <nullable.hpp>

Collaboration diagram for sparrow::nullable< T, B >:
[legend]

Public Types

using stored_value_type = T
 
using self_type = nullable<T, B>
 
using value_traits = nullable_traits<T>
 
using value_type = typename value_traits::value_type
 
using reference = typename value_traits::reference
 
using const_reference = typename value_traits::const_reference
 
using rvalue_reference = typename value_traits::rvalue_reference
 
using const_rvalue_reference = typename value_traits::const_rvalue_reference
 
using flag_traits = nullable_traits<B>
 
using flag_type = typename flag_traits::value_type
 
using flag_reference = typename flag_traits::reference
 
using flag_const_reference = typename flag_traits::const_reference
 
using flag_rvalue_reference = typename flag_traits::rvalue_reference
 
using flag_const_rvalue_reference = typename flag_traits::const_rvalue_reference
 

Public Member Functions

template<std::default_initializable U = T, std::default_initializable BB = B>
constexpr nullable () noexcept
 Default constructor creating a null nullable.
 
template<std::default_initializable U = T, std::default_initializable BB = B>
constexpr nullable (nullval_t) noexcept
 Constructor from nullval_t creating a null nullable.
 
template<class U>
requires (not std::same_as<self_type, std::decay_t<U>> and std::constructible_from<T, U &&>)
 explicit (not std::convertible_to< U &&, T >) const expr nullable(U &&value) noexcept(noexcept(T(std::declval< U >())))
 Constructor from a value creating a non-null nullable.
 
constexpr nullable (const self_type &rhs)=default
 Default copy constructor.
 
template<class TO, mpl::boolean_like BO>
requires (impl::both_constructible_from_cref<T, TO, B, BO> and not impl::initializable_from_refs<T, nullable<TO, BO>>)
 explicit (not impl::both_convertible_from_cref< T, TO, B, BO >) SPARROW_CONSTEXPR nullable(const nullable< TO
 Converting copy constructor from different nullable types.
 
BO m_null_flag (rhs.null_flag())
 
constexpr nullable (self_type &&rhs) noexcept=default
 Default move constructor.
 
template<class TO, mpl::boolean_like BO>
requires (impl::both_constructible_from_cond_ref<T, TO, B, BO> and not impl::initializable_from_refs<T, nullable<TO, BO>>)
 explicit (not impl::both_convertible_from_cond_ref< T, TO, B, BO >) SPARROW_CONSTEXPR nullable(nullable< TO
 Converting move constructor from different nullable types.
 
BO m_null_flag (std::move(rhs).null_flag())
 
constexpr nullable (value_type &&value, flag_type &&null_flag)
 Constructor from value and flag.
 
constexpr nullable (std::add_lvalue_reference_t< T > value, std::add_lvalue_reference_t< B > null_flag)
 Constructor from lvalue references (for reference semantics).
 
constexpr nullable (value_type &&value, std::add_lvalue_reference_t< B > null_flag)
 Constructor from moved value and flag reference.
 
constexpr nullable (std::add_lvalue_reference_t< T > value, flag_type &&null_flag)
 Constructor from value reference and moved flag.
 
constexpr self_typeoperator= (nullval_t) noexcept
 Assignment from nullval_t, setting nullable to null state.
 
template<class TO>
requires (not std::same_as<self_type, TO> and std::assignable_from<std::add_lvalue_reference_t<T>, TO>)
constexpr self_typeoperator= (TO &&rhs) noexcept
 Assignment from a value, setting nullable to non-null state.
 
constexpr self_typeoperator= (const self_type &rhs) noexcept
 Default copy assignment operator.
 
template<class TO, mpl::boolean_like BO>
requires ( impl::both_assignable_from_cref<T, TO, B, BO> and not impl::initializable_from_refs<T, nullable<TO, BO>> and not impl::assignable_from_refs<T, nullable<TO, BO>> )
constexpr self_typeoperator= (const nullable< TO, BO > &rhs) noexcept
 Converting assignment operator from different nullable types.
 
constexpr self_typeoperator= (self_type &&rhs) noexcept
 Default move assignment operator.
 
template<class TO, mpl::boolean_like BO>
requires ( impl::both_assignable_from_cond_ref<T, TO, B, BO> and not impl::initializable_from_refs<T, nullable<TO, BO>> and not impl::assignable_from_refs<T, nullable<TO, BO>> )
constexpr self_typeoperator= (nullable< TO, BO > &&rhs) noexcept
 Converting move assignment operator from different nullable types.
 
constexpr operator bool () const noexcept
 Conversion to bool indicating non-null state.
 
constexpr bool has_value () const noexcept
 Checks whether the nullable contains a valid value.
 
constexpr flag_reference null_flag () &noexcept
 Gets mutable reference to the validity flag.
 
constexpr flag_const_reference null_flag () const &noexcept
 Gets const reference to the validity flag.
 
constexpr flag_rvalue_reference null_flag () &&noexcept
 Gets rvalue reference to the validity flag.
 
constexpr flag_const_rvalue_reference null_flag () const &&noexcept
 Gets const rvalue reference to the validity flag.
 
constexpr reference get () &noexcept
 Gets mutable reference to the stored value.
 
constexpr const_reference get () const &noexcept
 Gets const reference to the stored value.
 
constexpr rvalue_reference get () &&noexcept
 Gets rvalue reference to the stored value.
 
constexpr const_rvalue_reference get () const &&noexcept
 Gets const rvalue reference to the stored value.
 
constexpr reference value () &
 Gets mutable reference to the value with null checking.
 
constexpr const_reference value () const &
 Gets const reference to the value with null checking.
 
constexpr rvalue_reference value () &&
 Gets rvalue reference to the value with null checking.
 
constexpr const_rvalue_reference value () const &&
 Gets const rvalue reference to the value with null checking.
 
template<class U>
constexpr value_type value_or (U &&default_value) const &
 Gets the value or a default if null (const version).
 
template<class U>
constexpr value_type value_or (U &&default_value) &&
 Gets the value or a default if null (rvalue version).
 
void swap (self_type &other) noexcept
 Swaps this nullable with another.
 
void reset () noexcept
 Resets the nullable to null state.
 
template<class U>
constexpr auto value_or (U &&default_value) const &-> value_type
 
template<class U>
constexpr auto value_or (U &&default_value) &&-> value_type
 

Public Attributes

BO & rhs: m_value(rhs.get())
 
BO && rhs: m_value(std::move(rhs).get())
 

Friends

template<class TO, mpl::boolean_like BO>
class nullable
 

Detailed Description

template<class T, mpl::boolean_like B = bool>
class sparrow::nullable< T, B >
Examples
/home/runner/work/sparrow/sparrow/include/sparrow/utils/nullable.hpp.

Definition at line 289 of file nullable.hpp.

Member Typedef Documentation

◆ const_reference

template<class T, mpl::boolean_like B = bool>
using sparrow::nullable< T, B >::const_reference = typename value_traits::const_reference

◆ const_rvalue_reference

template<class T, mpl::boolean_like B = bool>
using sparrow::nullable< T, B >::const_rvalue_reference = typename value_traits::const_rvalue_reference

◆ flag_const_reference

template<class T, mpl::boolean_like B = bool>
using sparrow::nullable< T, B >::flag_const_reference = typename flag_traits::const_reference

◆ flag_const_rvalue_reference

template<class T, mpl::boolean_like B = bool>
using sparrow::nullable< T, B >::flag_const_rvalue_reference = typename flag_traits::const_rvalue_reference

◆ flag_reference

template<class T, mpl::boolean_like B = bool>
using sparrow::nullable< T, B >::flag_reference = typename flag_traits::reference

◆ flag_rvalue_reference

template<class T, mpl::boolean_like B = bool>
using sparrow::nullable< T, B >::flag_rvalue_reference = typename flag_traits::rvalue_reference

◆ flag_traits

template<class T, mpl::boolean_like B = bool>
using sparrow::nullable< T, B >::flag_traits = nullable_traits<B>

◆ flag_type

template<class T, mpl::boolean_like B = bool>
using sparrow::nullable< T, B >::flag_type = typename flag_traits::value_type

◆ reference

template<class T, mpl::boolean_like B = bool>
using sparrow::nullable< T, B >::reference = typename value_traits::reference

◆ rvalue_reference

template<class T, mpl::boolean_like B = bool>
using sparrow::nullable< T, B >::rvalue_reference = typename value_traits::rvalue_reference

◆ self_type

template<class T, mpl::boolean_like B = bool>
using sparrow::nullable< T, B >::self_type = nullable<T, B>

◆ stored_value_type

template<class T, mpl::boolean_like B = bool>
using sparrow::nullable< T, B >::stored_value_type = T

◆ value_traits

template<class T, mpl::boolean_like B = bool>
using sparrow::nullable< T, B >::value_traits = nullable_traits<T>

◆ value_type

template<class T, mpl::boolean_like B = bool>
using sparrow::nullable< T, B >::value_type = typename value_traits::value_type

Constructor & Destructor Documentation

◆ nullable() [1/8]

template<class T, mpl::boolean_like B = bool>
template<std::default_initializable U = T, std::default_initializable BB = B>
sparrow::nullable< T, B >::nullable ( )
inlineconstexprnoexcept

Default constructor creating a null nullable.

Template Parameters
UValue type (deduced, must be default constructible)
BBFlag type (deduced, must be default constructible)
Precondition
T and B must be default constructible
Postcondition
has_value() returns false
get() returns default-constructed value
null_flag() returns false

Definition at line 320 of file nullable.hpp.

◆ nullable() [2/8]

template<class T, mpl::boolean_like B = bool>
template<std::default_initializable U = T, std::default_initializable BB = B>
sparrow::nullable< T, B >::nullable ( nullval_t )
inlineconstexprnoexcept

Constructor from nullval_t creating a null nullable.

Template Parameters
UValue type (deduced, must be default constructible)
BBFlag type (deduced, must be default constructible)
Precondition
T and B must be default constructible
Postcondition
has_value() returns false
get() returns default-constructed value
null_flag() returns false

Definition at line 338 of file nullable.hpp.

◆ nullable() [3/8]

template<class T, mpl::boolean_like B = bool>
sparrow::nullable< T, B >::nullable ( const self_type & rhs)
constexprdefault

Default copy constructor.

Parameters
rhsSource nullable to copy from
Precondition
rhs must be in a valid state
Postcondition
This nullable is an exact copy of rhs
has_value() equals rhs.has_value()
If non-null, get() equals rhs.get()

◆ nullable() [4/8]

template<class T, mpl::boolean_like B = bool>
sparrow::nullable< T, B >::nullable ( self_type && rhs)
constexprdefaultnoexcept

Default move constructor.

Parameters
rhsSource nullable to move from
Precondition
rhs must be in a valid state
Postcondition
This nullable is an exact copy of rhs
has_value() equals rhs.has_value()
If non-null, get() equals rhs.get()

◆ nullable() [5/8]

template<class T, mpl::boolean_like B = bool>
sparrow::nullable< T, B >::nullable ( value_type && value,
flag_type && null_flag )
inlineconstexpr

Constructor from value and flag.

Parameters
valueValue to move and store
null_flagFlag to move and store
Postcondition
get() returns the moved value
null_flag() returns the moved flag
Original value and flag are moved from

Definition at line 516 of file nullable.hpp.

◆ nullable() [6/8]

template<class T, mpl::boolean_like B = bool>
sparrow::nullable< T, B >::nullable ( std::add_lvalue_reference_t< T > value,
std::add_lvalue_reference_t< B > null_flag )
inlineconstexpr

Constructor from lvalue references (for reference semantics).

Parameters
valueReference to value to store
null_flagReference to flag to store
Postcondition
get() refers to the provided value reference
null_flag() refers to the provided flag reference
Changes to the nullable affect the referenced objects

Definition at line 532 of file nullable.hpp.

◆ nullable() [7/8]

template<class T, mpl::boolean_like B = bool>
sparrow::nullable< T, B >::nullable ( value_type && value,
std::add_lvalue_reference_t< B > null_flag )
inlineconstexpr

Constructor from moved value and flag reference.

Parameters
valueValue to move and store
null_flagReference to flag to store
Postcondition
get() returns the moved value
null_flag() refers to the provided flag reference

Definition at line 547 of file nullable.hpp.

◆ nullable() [8/8]

template<class T, mpl::boolean_like B = bool>
sparrow::nullable< T, B >::nullable ( std::add_lvalue_reference_t< T > value,
flag_type && null_flag )
inlineconstexpr

Constructor from value reference and moved flag.

Parameters
valueReference to value to store
null_flagFlag to move and store
Postcondition
get() refers to the provided value reference
null_flag() returns the moved flag

Definition at line 562 of file nullable.hpp.

Member Function Documentation

◆ explicit() [1/3]

template<class T, mpl::boolean_like B = bool>
template<class TO, mpl::boolean_like BO>
requires (impl::both_constructible_from_cond_ref<T, TO, B, BO> and not impl::initializable_from_refs<T, nullable<TO, BO>>)
sparrow::nullable< T, B >::explicit ( not impl::both_convertible_from_cond_ref< T, TO, B, BO > )

Converting move constructor from different nullable types.

Template Parameters
TOSource value type
BOSource flag type
Parameters
rhsSource nullable to move from
Precondition
T must be constructible from TO
B must be constructible from BO
TO must not be initializable from this nullable type (prevents ambiguity)
Postcondition
This nullable contains converted moves of rhs value and flag
has_value() equals rhs.has_value()
If non-null, get() is constructed from std::move(rhs).get()

◆ explicit() [2/3]

template<class T, mpl::boolean_like B = bool>
template<class TO, mpl::boolean_like BO>
requires (impl::both_constructible_from_cref<T, TO, B, BO> and not impl::initializable_from_refs<T, nullable<TO, BO>>)
sparrow::nullable< T, B >::explicit ( not impl::both_convertible_from_cref< T, TO, B, BO > ) const

Converting copy constructor from different nullable types.

Template Parameters
TOSource value type
BOSource flag type
Parameters
rhsSource nullable to copy from
Precondition
T must be constructible from TO
B must be constructible from BO
TO must not be initializable from this nullable type (prevents ambiguity)
Postcondition
This nullable contains converted copies of rhs value and flag
has_value() equals rhs.has_value()
If non-null, get() is constructed from rhs.get()

◆ explicit() [3/3]

template<class T, mpl::boolean_like B = bool>
template<class U>
requires (not std::same_as<self_type, std::decay_t<U>> and std::constructible_from<T, U &&>)
sparrow::nullable< T, B >::explicit ( not std::convertible_to< U &&, T > ) const &&
inlinenoexcept

Constructor from a value creating a non-null nullable.

Template Parameters
UType of the input value (must be constructible to T)
Parameters
valueValue to store
Precondition
U must be constructible to T
U must not be the same type as nullable (to avoid recursion)
Postcondition
has_value() returns true
get() returns the constructed value
null_flag() returns true

Definition at line 358 of file nullable.hpp.

◆ get() [1/4]

template<class T, mpl::boolean_like B>
auto sparrow::nullable< T, B >::get ( ) &&
nodiscardconstexprnoexcept

Gets rvalue reference to the stored value.

Returns
Rvalue reference to the value
Postcondition
If value is a reference type, returns the reference
If value is a value type, returns moved value

Definition at line 1224 of file nullable.hpp.

◆ get() [2/4]

template<class T, mpl::boolean_like B>
auto sparrow::nullable< T, B >::get ( ) &
nodiscardconstexprnoexcept

Gets mutable reference to the stored value.

Returns
Mutable reference to the value
Postcondition
Returned reference provides access to the stored value
Value is accessible regardless of null state
Modifications through reference affect stored value
Examples
/home/runner/work/sparrow/sparrow/include/sparrow/utils/nullable.hpp.

Definition at line 1212 of file nullable.hpp.

Here is the caller graph for this function:

◆ get() [3/4]

template<class T, mpl::boolean_like B>
auto sparrow::nullable< T, B >::get ( ) const &&
nodiscardconstexprnoexcept

Gets const rvalue reference to the stored value.

Returns
Const rvalue reference to the value
Postcondition
If value is a reference type, returns the reference
If value is a value type, returns moved const value

Definition at line 1237 of file nullable.hpp.

◆ get() [4/4]

template<class T, mpl::boolean_like B>
auto sparrow::nullable< T, B >::get ( ) const &
nodiscardconstexprnoexcept

Gets const reference to the stored value.

Returns
Const reference to the value
Postcondition
Returned reference provides read-only access to stored value
Value is accessible regardless of null state

Definition at line 1218 of file nullable.hpp.

◆ has_value()

template<class T, mpl::boolean_like B>
bool sparrow::nullable< T, B >::has_value ( ) const
nodiscardconstexprnoexcept

Checks whether the nullable contains a valid value.

Returns
true if nullable contains a valid value, false if null
Postcondition
Return value equals static_cast<bool>(*this)
Return value equals static_cast<bool>(null_flag())
Examples
/home/runner/work/sparrow/sparrow/include/sparrow/utils/nullable.hpp.

Definition at line 1168 of file nullable.hpp.

Here is the caller graph for this function:

◆ m_null_flag() [1/2]

template<class T, mpl::boolean_like B = bool>
BO sparrow::nullable< T, B >::m_null_flag ( rhs. null_flag())
inline

Definition at line 399 of file nullable.hpp.

◆ m_null_flag() [2/2]

template<class T, mpl::boolean_like B = bool>
BO sparrow::nullable< T, B >::m_null_flag ( std::move(rhs).null_flag() )
inline

Definition at line 468 of file nullable.hpp.

◆ null_flag() [1/4]

template<class T, mpl::boolean_like B>
auto sparrow::nullable< T, B >::null_flag ( ) &&
nodiscardconstexprnoexcept

Gets rvalue reference to the validity flag.

Returns
Rvalue reference to the flag
Postcondition
If flag is a reference type, returns the reference
If flag is a value type, returns moved flag

Definition at line 1186 of file nullable.hpp.

◆ null_flag() [2/4]

template<class T, mpl::boolean_like B>
auto sparrow::nullable< T, B >::null_flag ( ) &
nodiscardconstexprnoexcept

Gets mutable reference to the validity flag.

Returns
Mutable reference to the flag
Postcondition
Returned reference can be used to modify the null state
Changes to the flag affect has_value() result
Examples
/home/runner/work/sparrow/sparrow/include/sparrow/utils/nullable.hpp.

Definition at line 1174 of file nullable.hpp.

◆ null_flag() [3/4]

template<class T, mpl::boolean_like B>
auto sparrow::nullable< T, B >::null_flag ( ) const &&
nodiscardconstexprnoexcept

Gets const rvalue reference to the validity flag.

Returns
Const rvalue reference to the flag
Postcondition
If flag is a reference type, returns the reference
If flag is a value type, returns moved const flag

Definition at line 1199 of file nullable.hpp.

◆ null_flag() [4/4]

template<class T, mpl::boolean_like B>
auto sparrow::nullable< T, B >::null_flag ( ) const &
nodiscardconstexprnoexcept

Gets const reference to the validity flag.

Returns
Const reference to the flag
Postcondition
Returned reference reflects current null state

Definition at line 1180 of file nullable.hpp.

◆ operator bool()

template<class T, mpl::boolean_like B>
sparrow::nullable< T, B >::operator bool ( ) const
explicitconstexprnoexcept

Conversion to bool indicating non-null state.

Returns
true if nullable contains a valid value, false if null
Postcondition
Return value equals has_value()
Return value equals static_cast<bool>(null_flag())

Definition at line 1162 of file nullable.hpp.

Here is the call graph for this function:

◆ operator=() [1/6]

template<class T, mpl::boolean_like B = bool>
template<class TO, mpl::boolean_like BO>
requires ( impl::both_assignable_from_cref<T, TO, B, BO> and not impl::initializable_from_refs<T, nullable<TO, BO>> and not impl::assignable_from_refs<T, nullable<TO, BO>> )
self_type & sparrow::nullable< T, B >::operator= ( const nullable< TO, BO > & rhs)
inlineconstexprnoexcept

Converting assignment operator from different nullable types.

Template Parameters
TOSource value type
BOSource flag type
Parameters
rhsSource nullable to copy from
Returns
Reference to this nullable
Precondition
T must be constructible from TO
B must be constructible from BO
TO must not be initializable from this nullable type (prevents ambiguity)
Postcondition
This nullable contains converted copies of rhs value and flag
has_value() equals rhs.has_value()
If non-null, get() is constructed from rhs.get()

Definition at line 645 of file nullable.hpp.

◆ operator=() [2/6]

template<class T, mpl::boolean_like B = bool>
self_type & sparrow::nullable< T, B >::operator= ( const self_type & rhs)
inlineconstexprnoexcept

Default copy assignment operator.

Parameters
rhsSource nullable to copy from
Returns
Reference to this nullable
Precondition
rhs must be in a valid state
Postcondition
This nullable is an exact copy of rhs
has_value() equals rhs.has_value()
get() is assigned from rhs.get()

Definition at line 617 of file nullable.hpp.

◆ operator=() [3/6]

template<class T, mpl::boolean_like B = bool>
template<class TO, mpl::boolean_like BO>
requires ( impl::both_assignable_from_cond_ref<T, TO, B, BO> and not impl::initializable_from_refs<T, nullable<TO, BO>> and not impl::assignable_from_refs<T, nullable<TO, BO>> )
self_type & sparrow::nullable< T, B >::operator= ( nullable< TO, BO > && rhs)
inlineconstexprnoexcept

Converting move assignment operator from different nullable types.

Template Parameters
TOSource value type
BOSource flag type
Parameters
rhsSource nullable to move from
Returns
Reference to this nullable
Precondition
T must be constructible from TO
B must be constructible from BO
TO must not be initializable from this nullable type (prevents ambiguity)
Postcondition
This nullable contains converted moves of rhs value and flag
has_value() equals rhs.has_value()
If non-null, get() is constructed from std::move(rhs).get()

Definition at line 691 of file nullable.hpp.

◆ operator=() [4/6]

template<class T, mpl::boolean_like B = bool>
self_type & sparrow::nullable< T, B >::operator= ( nullval_t )
inlineconstexprnoexcept

Assignment from nullval_t, setting nullable to null state.

Parameters
nullval_tnullval sentinel value
Returns
Reference to this nullable
Postcondition
has_value() returns false
null_flag() returns false
get() remains accessible but semantically invalid
Examples
/home/runner/work/sparrow/sparrow/include/sparrow/utils/nullable.hpp.

Definition at line 578 of file nullable.hpp.

◆ operator=() [5/6]

template<class T, mpl::boolean_like B = bool>
self_type & sparrow::nullable< T, B >::operator= ( self_type && rhs)
inlineconstexprnoexcept

Default move assignment operator.

Parameters
rhsSource nullable to move from
Returns
Reference to this nullable
Precondition
rhs must be in a valid state
Postcondition
This nullable is an exact copy of rhs
has_value() equals rhs.has_value()
get() is assigned from std::move(rhs).get()

Definition at line 663 of file nullable.hpp.

◆ operator=() [6/6]

template<class T, mpl::boolean_like B = bool>
template<class TO>
requires (not std::same_as<self_type, TO> and std::assignable_from<std::add_lvalue_reference_t<T>, TO>)
self_type & sparrow::nullable< T, B >::operator= ( TO && rhs)
inlineconstexprnoexcept

Assignment from a value, setting nullable to non-null state.

Template Parameters
TOType of the assigned value
Parameters
rhsValue to assign
Returns
Reference to this nullable
Precondition
TO must not be the same as nullable type
TO must be assignable to T
Postcondition
has_value() returns true
get() contains the assigned value
null_flag() returns true

Definition at line 599 of file nullable.hpp.

◆ reset()

template<class T, mpl::boolean_like B>
void sparrow::nullable< T, B >::reset ( )
noexcept

Resets the nullable to null state.

Postcondition
has_value() returns false
null_flag() returns false
get() remains accessible but semantically invalid
Examples
/home/runner/work/sparrow/sparrow/include/sparrow/utils/nullable.hpp.

Definition at line 1300 of file nullable.hpp.

◆ swap()

template<class T, mpl::boolean_like B>
void sparrow::nullable< T, B >::swap ( self_type & other)
noexcept

Swaps this nullable with another.

Parameters
otherNullable to swap with
Postcondition
This nullable contains other's previous value and flag
other contains this nullable's previous value and flag
Examples
/home/runner/work/sparrow/sparrow/include/sparrow/utils/nullable.hpp.

Definition at line 1292 of file nullable.hpp.

Here is the call graph for this function:

◆ value() [1/4]

template<class T, mpl::boolean_like B>
auto sparrow::nullable< T, B >::value ( ) &
nodiscardconstexpr

Gets mutable reference to the value with null checking.

Returns
Mutable reference to the value
Precondition
has_value() must be true
Postcondition
Returns reference to the stored value
Exceptions
bad_nullable_accessif has_value() is false
Examples
/home/runner/work/sparrow/sparrow/include/sparrow/utils/nullable.hpp.

Definition at line 1250 of file nullable.hpp.

Here is the call graph for this function:

◆ value() [2/4]

template<class T, mpl::boolean_like B>
auto sparrow::nullable< T, B >::value ( ) &&
nodiscardconstexpr

Gets rvalue reference to the value with null checking.

Returns
Rvalue reference to the value
Precondition
has_value() must be true
Postcondition
Returns rvalue reference to the stored value
If value type, original value is moved from
Exceptions
bad_nullable_accessif has_value() is false

Definition at line 1264 of file nullable.hpp.

◆ value() [3/4]

template<class T, mpl::boolean_like B>
auto sparrow::nullable< T, B >::value ( ) const &
nodiscardconstexpr

Gets const reference to the value with null checking.

Returns
Const reference to the value
Precondition
has_value() must be true
Postcondition
Returns const reference to the stored value
Exceptions
bad_nullable_accessif has_value() is false

Definition at line 1257 of file nullable.hpp.

Here is the call graph for this function:

◆ value() [4/4]

template<class T, mpl::boolean_like B>
auto sparrow::nullable< T, B >::value ( ) const &&
nodiscardconstexpr

Gets const rvalue reference to the value with null checking.

Returns
Const rvalue reference to the value
Precondition
has_value() must be true
Postcondition
Returns const rvalue reference to the stored value
Exceptions
bad_nullable_accessif has_value() is false

Definition at line 1271 of file nullable.hpp.

◆ value_or() [1/4]

template<class T, mpl::boolean_like B = bool>
template<class U>
value_type sparrow::nullable< T, B >::value_or ( U && default_value) &&
nodiscardconstexpr

Gets the value or a default if null (rvalue version).

Template Parameters
UType of the default value
Parameters
default_valueValue to return if nullable is null
Returns
Moved stored value if non-null, otherwise default_value
Precondition
U must be convertible to value_type
Postcondition
If has_value() is true, returns moved stored value
If has_value() is false, returns converted default_value

◆ value_or() [2/4]

template<class T, mpl::boolean_like B = bool>
template<class U>
auto sparrow::nullable< T, B >::value_or ( U && default_value) && -> value_type
constexpr

Definition at line 1286 of file nullable.hpp.

◆ value_or() [3/4]

template<class T, mpl::boolean_like B = bool>
template<class U>
value_type sparrow::nullable< T, B >::value_or ( U && default_value) const &
nodiscardconstexpr

Gets the value or a default if null (const version).

Template Parameters
UType of the default value
Parameters
default_valueValue to return if nullable is null
Returns
Stored value if non-null, otherwise default_value
Precondition
U must be convertible to value_type
Postcondition
If has_value() is true, returns copy of stored value
If has_value() is false, returns converted default_value
Examples
/home/runner/work/sparrow/sparrow/include/sparrow/utils/nullable.hpp.

◆ value_or() [4/4]

template<class T, mpl::boolean_like B = bool>
template<class U>
auto sparrow::nullable< T, B >::value_or ( U && default_value) const & -> value_type
constexpr

Definition at line 1279 of file nullable.hpp.

Friends And Related Symbol Documentation

◆ nullable

template<class T, mpl::boolean_like B = bool>
template<class TO, mpl::boolean_like BO>
friend class nullable
friend

Member Data Documentation

◆ rhs [1/2]

template<class T, mpl::boolean_like B = bool>
BO& sparrow::nullable< T, B >::rhs

◆ rhs [2/2]

template<class T, mpl::boolean_like B = bool>
BO&& sparrow::nullable< T, B >::rhs

Definition at line 465 of file nullable.hpp.


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