Simple-Utility v2.3.1
Loading...
Searching...
No Matches
sl::nullables::adapter< TNull, TAdapted > Class Template Reference

A adapter class, mimic the behaviour of nullable types. More...

#include <adapter.hpp>

Collaboration diagram for sl::nullables::adapter< TNull, TAdapted >:
[legend]

Public Types

using adapted_type = TAdapted
 
using value_type = adapted_value_t< TAdapted >
 
using null_type = TNull
 

Public Member Functions

constexpr ~adapter () noexcept=default
 Default destructor.
 
constexpr adapter (const adapter &other) noexcept(std::is_nothrow_copy_constructible_v< TNull > &&std::is_nothrow_copy_constructible_v< TAdapted >)=default
 Default copy constructor.
 
constexpr adapteroperator= (const adapter &other) noexcept(std::is_nothrow_copy_assignable_v< TNull > &&std::is_nothrow_copy_assignable_v< TAdapted >)=default
 Default copy assignment operator.
 
constexpr adapter (adapter &&other) noexcept(std::is_nothrow_move_constructible_v< TNull > &&std::is_nothrow_move_constructible_v< TAdapted >)=default
 Default move constructor.
 
constexpr adapteroperator= (adapter &&other) noexcept(std::is_nothrow_move_assignable_v< TNull > &&std::is_nothrow_move_assignable_v< TAdapted >)=default
 Default move assignment operator.
 
template<concepts::initializes< null_type > TNullArg>
requires std::constructible_from<adapted_type, const null_type&>
constexpr adapter (in_place_null_t, TNullArg &&nullArg) noexcept(std::is_nothrow_constructible_v< null_type, TNullArg > &&std::is_nothrow_constructible_v< adapted_type, const null_type & >)
 Constructs the null object with the given argument and then constructs the adapted object with the null object.
 
constexpr adapter (adapter_null_t) noexcept(std::is_nothrow_default_constructible_v< null_type > &&std::is_nothrow_constructible_v< adapted_type, null_type & >)
 Default constructs the null object and then constructs the adapted object with the null object.
 
template<concepts::initializes< null_type > TNullArg>
requires concepts::not_same_as<adapter_null_t, std::remove_cvref_t<TNullArg>> && concepts::not_same_as<in_place_null_t, std::remove_cvref_t<TNullArg>> && (!detail::convertible_to_adapter<TNullArg>) && std::constructible_from<adapted_type, const null_type&>
constexpr adapter (TNullArg &&nullArg) noexcept(std::is_nothrow_constructible_v< adapter, std::in_place_t, TNullArg >)
 Constructs the null object with the given argument and then constructs the adapted object with the null object.
 
template<concepts::initializes< null_type > TNullArg, concepts::initializes< adapted_type > TAdaptedArg>
requires concepts::not_same_as<adapter_null_t, std::remove_cvref_t<TNullArg>> && concepts::not_same_as<in_place_null_t, std::remove_cvref_t<TNullArg>> && concepts::not_same_as<adapter_null_t, std::remove_cvref_t<TAdaptedArg>> && concepts::not_same_as<in_place_null_t, std::remove_cvref_t<TAdaptedArg>>
constexpr adapter (TNullArg &&nullArg, TAdaptedArg &&adaptedArg) noexcept(std::is_nothrow_constructible_v< null_type, TNullArg > &&std::is_nothrow_constructible_v< adapted_type, TAdaptedArg >)
 Constructs the null object and the adapted with the given arguments.
 
template<detail::convertible_to_adapter TArg>
requires concepts::not_same_as<adapter_null_t, std::remove_cvref_t<TArg>> && concepts::not_same_as<in_place_null_t, std::remove_cvref_t<TArg>>
constexpr adapter (TArg &&arg) noexcept(noexcept(to_nullables_adapter(std::forward< TArg >(arg))) &&std::is_nothrow_constructible_v< adapter >)
 Constructs the adapter with the result of a to_nullables_adapter invocation.
 
constexpr adapteroperator= (adapter_null_t) noexcept(std::is_nothrow_assignable_v< adapted_type &, null_type & >)
 Assigns null to the adapted object.
 
template<concepts::assignable_to< adapted_type & > TAdaptedArg>
requires concepts::not_same_as<adapter_null_t, std::remove_cvref_t<TAdaptedArg>>
constexpr adapteroperator= (TAdaptedArg &&adaptedArg) noexcept(std::is_nothrow_assignable_v< adapted_type &, TAdaptedArg >)
 Assigns the adapted object.
 
constexpr decltype(auto) operator* () const &
 Retrieves the value from the adapted object.
 
constexpr decltype(auto) operator* () &
 Retrieves the value from the adapted object.
 
constexpr decltype(auto) operator* () &&
 Retrieves the value from the adapted object.
 
constexpr bool operator== (adapter_null_t) const noexcept(concepts::nothrow_weakly_equality_comparable_with< TAdapted, TNull >)
 Comparison operator with its adapter_null`object.
 

Related Functions

(Note that these are not member functions.)

constexpr adapter_null_t adapter_null {}
 Dedicated null object for adapters.
 
constexpr in_place_null_t in_place_null {}
 Tag object for adapters, which can be used to disambiguate the construction with just a null-object.
 
constexpr detail::to_nullables_adapter_fn to_nullables_adapter {}
 Converts the given argument to a adapter object.
 
template<class TNull , class TAdapted >
 adapter (TNull, TAdapted) -> adapter< TNull, TAdapted >
 Deduction guide.
 
template<class T >
 adapter (T &&t) -> adapter< typename std::remove_cvref_t< decltype(to_nullables_adapter(std::declval< T >()))>::null_type, typename std::remove_cvref_t< decltype(to_nullables_adapter(std::declval< T >()))>::adapted_type >
 Deduction guide, which makes use of to_nullables_adapter customization point.
 

Detailed Description

template<class TNull, adaptable_with< TNull > TAdapted>
requires std::same_as<TNull, std::remove_cvref_t<TNull>> && std::same_as<TAdapted, std::remove_cvref_t<TAdapted>>
class sl::nullables::adapter< TNull, TAdapted >

A adapter class, mimic the behaviour of nullable types.

Template Parameters
TNullThe null type.
TAdaptedThe adapted type.

This class aims to provide a layer of abstraction for types, which logically have a null-state but no dedicated null-object to compare with. For example an arbitrary iterator can be compared to its end iterator, but that end iterator usually must be retrieved from the container (unless end iterator is a dedicated sentinel type). adapter aims to fill the gap and therefore accepts a state object and a null object. The adapter itself can be then compared to its dedicated adapter_null object and thus satisfying at least the input_nullable concept. If the state object is then initializable and constructible via the given null-object, the nullable concept is also satisfied.

Member Typedef Documentation

◆ adapted_type

template<class TNull , adaptable_with< TNull > TAdapted>
using sl::nullables::adapter< TNull, TAdapted >::adapted_type = TAdapted

◆ null_type

template<class TNull , adaptable_with< TNull > TAdapted>
using sl::nullables::adapter< TNull, TAdapted >::null_type = TNull

◆ value_type

template<class TNull , adaptable_with< TNull > TAdapted>
using sl::nullables::adapter< TNull, TAdapted >::value_type = adapted_value_t<TAdapted>

Constructor & Destructor Documentation

◆ ~adapter()

template<class TNull , adaptable_with< TNull > TAdapted>
constexpr sl::nullables::adapter< TNull, TAdapted >::~adapter ( )
constexprdefaultnoexcept

Default destructor.

◆ adapter() [1/7]

template<class TNull , adaptable_with< TNull > TAdapted>
constexpr sl::nullables::adapter< TNull, TAdapted >::adapter ( const adapter< TNull, TAdapted > &  other) const &&
constexprdefaultnoexcept

Default copy constructor.

Parameters
otherThe other adapter.

◆ adapter() [2/7]

template<class TNull , adaptable_with< TNull > TAdapted>
constexpr sl::nullables::adapter< TNull, TAdapted >::adapter ( adapter< TNull, TAdapted > &&  other) const &&
constexprdefaultnoexcept

Default move constructor.

Parameters
otherThe other adapter.

◆ adapter() [3/7]

template<class TNull , adaptable_with< TNull > TAdapted>
template<concepts::initializes< null_type > TNullArg>
requires std::constructible_from<adapted_type, const null_type&>
constexpr sl::nullables::adapter< TNull, TAdapted >::adapter ( in_place_null_t  ,
TNullArg &&  nullArg 
)
inlineexplicitconstexprnoexcept

Constructs the null object with the given argument and then constructs the adapted object with the null object.

Template Parameters
TNullArgThe constructor argument type for the null object.
Parameters
nullArgThe constructor argument for the null object.
Attention
The behaviour is undefined if after the construction adapted does not compare equal to the null object.

◆ adapter() [4/7]

template<class TNull , adaptable_with< TNull > TAdapted>
constexpr sl::nullables::adapter< TNull, TAdapted >::adapter ( adapter_null_t  )
inlineexplicitconstexprnoexcept

Default constructs the null object and then constructs the adapted object with the null object.

Attention
The behaviour is undefined if after the construction adapted does not compare equal to the null object.

◆ adapter() [5/7]

template<class TNull , adaptable_with< TNull > TAdapted>
template<concepts::initializes< null_type > TNullArg>
requires concepts::not_same_as<adapter_null_t, std::remove_cvref_t<TNullArg>> && concepts::not_same_as<in_place_null_t, std::remove_cvref_t<TNullArg>> && (!detail::convertible_to_adapter<TNullArg>) && std::constructible_from<adapted_type, const null_type&>
constexpr sl::nullables::adapter< TNull, TAdapted >::adapter ( TNullArg &&  nullArg)
inlineexplicitconstexprnoexcept

Constructs the null object with the given argument and then constructs the adapted object with the null object.

Template Parameters
TNullArgThe constructor argument type for the null object.
Parameters
nullArgThe constructor argument for the null object.
Attention
The behaviour is undefined if after the construction adapted does not compare equal to the null object.

◆ adapter() [6/7]

template<class TNull , adaptable_with< TNull > TAdapted>
template<concepts::initializes< null_type > TNullArg, concepts::initializes< adapted_type > TAdaptedArg>
requires concepts::not_same_as<adapter_null_t, std::remove_cvref_t<TNullArg>> && concepts::not_same_as<in_place_null_t, std::remove_cvref_t<TNullArg>> && concepts::not_same_as<adapter_null_t, std::remove_cvref_t<TAdaptedArg>> && concepts::not_same_as<in_place_null_t, std::remove_cvref_t<TAdaptedArg>>
constexpr sl::nullables::adapter< TNull, TAdapted >::adapter ( TNullArg &&  nullArg,
TAdaptedArg &&  adaptedArg 
)
inlineconstexprnoexcept

Constructs the null object and the adapted with the given arguments.

Template Parameters
TNullArgThe constructor argument type for the null object.
TAdaptedArgThe constructor argument type for the adapted object.
Parameters
nullArgThe constructor argument for the null object.
adaptedArgThe constructor argument for the adapted object.

◆ adapter() [7/7]

template<class TNull , adaptable_with< TNull > TAdapted>
template<detail::convertible_to_adapter TArg>
requires concepts::not_same_as<adapter_null_t, std::remove_cvref_t<TArg>> && concepts::not_same_as<in_place_null_t, std::remove_cvref_t<TArg>>
constexpr sl::nullables::adapter< TNull, TAdapted >::adapter ( TArg &&  arg)
inlineexplicitconstexprnoexcept

Constructs the adapter with the result of a to_nullables_adapter invocation.

Template Parameters
TArgThe argument type.
Parameters
argThe argument.
Note
This function makes use of the customization point to_nullables_adapter, which may be hooked by users.

Member Function Documentation

◆ operator*() [1/3]

template<class TNull , adaptable_with< TNull > TAdapted>
constexpr decltype(auto) sl::nullables::adapter< TNull, TAdapted >::operator* ( ) &
inlineconstexpr

Retrieves the value from the adapted object.

Note
This function makes use of the unwrap_adapter customization point, which may be hooked by users.
Attention
If the adapted object compares equal to the null object, the behaviour is undefined.
Returns
Returns the result as received.

◆ operator*() [2/3]

template<class TNull , adaptable_with< TNull > TAdapted>
constexpr decltype(auto) sl::nullables::adapter< TNull, TAdapted >::operator* ( ) &&
inlineconstexpr

Retrieves the value from the adapted object.

Note
This function makes use of the unwrap_adapter customization point, which may be hooked by users.
Attention
If the adapted object compares equal to the null object, the behaviour is undefined.
Returns
Returns the result as received.

◆ operator*() [3/3]

template<class TNull , adaptable_with< TNull > TAdapted>
constexpr decltype(auto) sl::nullables::adapter< TNull, TAdapted >::operator* ( ) const &
inlineconstexpr

Retrieves the value from the adapted object.

Note
This function makes use of the unwrap_adapter customization point, which may be hooked by users.
Attention
If the adapted object compares equal to the null object, the behaviour is undefined.
Returns
Returns the result as received.

◆ operator=() [1/4]

template<class TNull , adaptable_with< TNull > TAdapted>
constexpr adapter & sl::nullables::adapter< TNull, TAdapted >::operator= ( adapter< TNull, TAdapted > &&  other) &&
constexprdefaultnoexcept

Default move assignment operator.

Parameters
otherThe other adapter.

◆ operator=() [2/4]

template<class TNull , adaptable_with< TNull > TAdapted>
constexpr adapter & sl::nullables::adapter< TNull, TAdapted >::operator= ( adapter_null_t  )
inlineconstexprnoexcept

Assigns null to the adapted object.

Attention
The behaviour is undefined if adapted does not compare equal to the null object after the assignment.
Returns
Reference to this.

◆ operator=() [3/4]

template<class TNull , adaptable_with< TNull > TAdapted>
constexpr adapter & sl::nullables::adapter< TNull, TAdapted >::operator= ( const adapter< TNull, TAdapted > &  other) &&
constexprdefaultnoexcept

Default copy assignment operator.

Parameters
otherThe other adapter.

◆ operator=() [4/4]

template<class TNull , adaptable_with< TNull > TAdapted>
template<concepts::assignable_to< adapted_type & > TAdaptedArg>
requires concepts::not_same_as<adapter_null_t, std::remove_cvref_t<TAdaptedArg>>
constexpr adapter & sl::nullables::adapter< TNull, TAdapted >::operator= ( TAdaptedArg &&  adaptedArg)
inlineconstexprnoexcept

Assigns the adapted object.

Returns
Reference to this.

◆ operator==()

template<class TNull , adaptable_with< TNull > TAdapted>
constexpr bool sl::nullables::adapter< TNull, TAdapted >::operator== ( adapter_null_t  ) const
inlineconstexprnoexcept

Comparison operator with its adapter_null`object.

Returns
Returns true if the adapted object compares equal to the null object.

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