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

The nullable class models a value or a reference that can be "null", or missing, like values traditionally used in data science libraries. More...

#include <nullable.hpp>

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

Public Types

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
 
template<std::default_initializable U = T, std::default_initializable BB = B>
constexpr nullable (nullval_t) noexcept
 
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 >())))
 
constexpr nullable (const self_type &)=default
 
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
 
BO m_null_flag (rhs.null_flag())
 
constexpr nullable (self_type &&) noexcept=default
 
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
 
BO m_null_flag (std::move(rhs).null_flag())
 
constexpr nullable (value_type &&value, flag_type &&null_flag)
 
constexpr nullable (std::add_lvalue_reference_t< T > value, std::add_lvalue_reference_t< B > null_flag)
 
constexpr nullable (value_type &&value, std::add_lvalue_reference_t< B > null_flag)
 
constexpr nullable (std::add_lvalue_reference_t< T > value, flag_type &&null_flag)
 
constexpr self_typeoperator= (nullval_t) noexcept
 
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
 
constexpr self_typeoperator= (const self_type &rhs) noexcept
 
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
 
constexpr self_typeoperator= (self_type &&rhs) noexcept
 
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
 
constexpr operator bool () const noexcept
 
constexpr bool has_value () const noexcept
 
constexpr flag_reference null_flag () &noexcept
 
constexpr flag_const_reference null_flag () const &noexcept
 
constexpr flag_rvalue_reference null_flag () &&noexcept
 
constexpr flag_const_rvalue_reference null_flag () const &&noexcept
 
constexpr reference get () &noexcept
 
constexpr const_reference get () const &noexcept
 
constexpr rvalue_reference get () &&noexcept
 
constexpr const_rvalue_reference get () const &&noexcept
 
constexpr reference value () &
 
constexpr const_reference value () const &
 
constexpr rvalue_reference value () &&
 
constexpr const_rvalue_reference value () const &&
 
template<class U>
constexpr value_type value_or (U &&default_value) const &
 
template<class U>
constexpr value_type value_or (U &&default_value) &&
 
void swap (self_type &other) noexcept
 
void reset () noexcept
 
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 >

The nullable class models a value or a reference that can be "null", or missing, like values traditionally used in data science libraries.

The flag indicating whether the element should be considered missing can be a boolean-like value or reference.

The value is always valid, independently from the value of the flag. The flag only indicates whether the value should be considered as specified (flag is true) or null (flag is false). Assigning nullval to a nullable or setting its flag to flase does not trigger the destruction of the underlying value.

When the stored object is not a reference, the nullable class has a regular value semantics: copying or moving it will copy or move the underlying value and flag. When the stored object is a reference, the nullable class has a view semantics: copying it or moving it will copy the underlying value and flag instead of reassigining the references. This allows to create nullable views over two distinct arrays (one for the values, one for the flags) used to implement a stl-like contianer of nullable. For instance, if you have the following class:

template <class T, class B>
class nullable_array
{
private:
std::vector<T> m_values;
std::vector<bool> m_flags;
public:
reference operator[](size_type i)
{
return reference(m_values[i], m_flags[i]);
}
const_reference operator[](size_type i) const
{
return const_reference(m_values[i], m_flags[i]);
}
// ...
};
typename value_traits::const_reference const_reference
Definition nullable.hpp:288
friend class nullable
Definition nullable.hpp:487
typename value_traits::reference reference
Definition nullable.hpp:287

Then you want the same semantic for accessing elements of nullable_array as that of std::vector, meaning that the following:

nullable_array my_array = { ... };
my_array[1] = my_array[0];

should copy the underlying value and flag of the first element of my_array to the underlying value and flag of the second element of the array.

Template Parameters
Tthe type of the value
Bthe type of the flag. This type must be convertible to and assignable from bool

Definition at line 280 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

Definition at line 288 of file nullable.hpp.

◆ 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

Definition at line 290 of file nullable.hpp.

◆ flag_const_reference

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

Definition at line 294 of file nullable.hpp.

◆ 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

Definition at line 296 of file nullable.hpp.

◆ flag_reference

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

Definition at line 293 of file nullable.hpp.

◆ flag_rvalue_reference

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

Definition at line 295 of file nullable.hpp.

◆ flag_traits

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

Definition at line 291 of file nullable.hpp.

◆ flag_type

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

Definition at line 292 of file nullable.hpp.

◆ reference

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

Definition at line 287 of file nullable.hpp.

◆ rvalue_reference

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

Definition at line 289 of file nullable.hpp.

◆ self_type

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

Definition at line 284 of file nullable.hpp.

◆ value_traits

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

Definition at line 285 of file nullable.hpp.

◆ value_type

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

Definition at line 286 of file nullable.hpp.

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

Definition at line 299 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

Definition at line 306 of file nullable.hpp.

◆ nullable() [3/8]

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

◆ nullable() [4/8]

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

◆ nullable() [5/8]

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

Definition at line 373 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

Definition at line 379 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

Definition at line 385 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

Definition at line 391 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 > )

◆ 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

◆ 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

Definition at line 314 of file nullable.hpp.

◆ get() [1/4]

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

Definition at line 634 of file nullable.hpp.

◆ get() [2/4]

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

Definition at line 622 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

Definition at line 647 of file nullable.hpp.

◆ get() [4/4]

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

Definition at line 628 of file nullable.hpp.

◆ has_value()

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

Definition at line 578 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 331 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 356 of file nullable.hpp.

◆ null_flag() [1/4]

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

Definition at line 596 of file nullable.hpp.

◆ null_flag() [2/4]

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

Definition at line 584 of file nullable.hpp.

◆ null_flag() [3/4]

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

Definition at line 609 of file nullable.hpp.

◆ null_flag() [4/4]

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

Definition at line 590 of file nullable.hpp.

◆ operator bool()

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

Definition at line 572 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

Definition at line 425 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

Definition at line 412 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

Definition at line 445 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

Definition at line 397 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

Definition at line 432 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

Definition at line 405 of file nullable.hpp.

◆ reset()

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

Definition at line 710 of file nullable.hpp.

◆ swap()

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

Definition at line 702 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

Definition at line 660 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

Definition at line 674 of file nullable.hpp.

◆ value() [3/4]

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

Definition at line 667 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

Definition at line 681 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

◆ 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 696 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

◆ 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 689 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

Definition at line 487 of file nullable.hpp.

Member Data Documentation

◆ rhs [1/2]

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

Definition at line 328 of file nullable.hpp.

◆ rhs [2/2]

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

Definition at line 353 of file nullable.hpp.


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