The nullable class models a value or a reference that can be "null", or missing, like values traditionally used in data science libraries.
More...
|
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_type & | operator= (nullval_t) |
|
template<class TO>
requires (not std::same_as<self_type, TO> and std::assignable_from<std::add_lvalue_reference_t<T>, TO>) |
constexpr self_type & | operator= (TO &&rhs) |
|
constexpr self_type & | operator= (const self_type &rhs) |
|
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_type & | operator= (const nullable< TO, BO > &rhs) |
|
constexpr self_type & | operator= (self_type &&rhs) |
|
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_type & | operator= (nullable< TO, BO > &&rhs) |
|
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 |
|
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:
{
}
const_reference operator[](size_type i) const
{
return const_reference(m_values[i], m_flags[i]);
}
};
typename value_traits::const_reference const_reference
typename value_traits::reference reference
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
-
T | the type of the value |
B | the type of the flag. This type must be convertible to and assignable from bool |
Definition at line 279 of file nullable.hpp.