Simple-Utility v2.3.1
|
A adapter class, mimic the behaviour of nullable types. More...
#include <adapter.hpp>
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 adapter & | operator= (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 adapter & | operator= (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 adapter & | operator= (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 adapter & | operator= (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. | |
A adapter class, mimic the behaviour of nullable types.
TNull | The null type. |
TAdapted | The 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.
using sl::nullables::adapter< TNull, TAdapted >::adapted_type = TAdapted |
using sl::nullables::adapter< TNull, TAdapted >::null_type = TNull |
using sl::nullables::adapter< TNull, TAdapted >::value_type = adapted_value_t<TAdapted> |
|
constexprdefaultnoexcept |
Default destructor.
|
constexprdefaultnoexcept |
Default copy constructor.
other | The other adapter. |
|
constexprdefaultnoexcept |
Default move constructor.
other | The other adapter. |
|
inlineexplicitconstexprnoexcept |
Constructs the null object with the given argument and then constructs the adapted object with the null object.
TNullArg | The constructor argument type for the null object. |
nullArg | The constructor argument for the null object. |
|
inlineexplicitconstexprnoexcept |
Default constructs the null object and then constructs the adapted object with the null object.
|
inlineexplicitconstexprnoexcept |
Constructs the null object with the given argument and then constructs the adapted object with the null object.
TNullArg | The constructor argument type for the null object. |
nullArg | The constructor argument for the null object. |
|
inlineconstexprnoexcept |
Constructs the null object and the adapted with the given arguments.
TNullArg | The constructor argument type for the null object. |
TAdaptedArg | The constructor argument type for the adapted object. |
nullArg | The constructor argument for the null object. |
adaptedArg | The constructor argument for the adapted object. |
|
inlineexplicitconstexprnoexcept |
Constructs the adapter with the result of a to_nullables_adapter
invocation.
TArg | The argument type. |
arg | The argument. |
to_nullables_adapter
, which may be hooked by users.
|
inlineconstexpr |
Retrieves the value from the adapted object.
unwrap_adapter
customization point, which may be hooked by users.
|
inlineconstexpr |
Retrieves the value from the adapted object.
unwrap_adapter
customization point, which may be hooked by users.
|
inlineconstexpr |
Retrieves the value from the adapted object.
unwrap_adapter
customization point, which may be hooked by users.
|
constexprdefaultnoexcept |
Default move assignment operator.
other | The other adapter. |
|
inlineconstexprnoexcept |
Assigns null to the adapted object.
|
constexprdefaultnoexcept |
Default copy assignment operator.
other | The other adapter. |
|
inlineconstexprnoexcept |
Assigns the adapted object.
|
inlineconstexprnoexcept |
Comparison operator with its adapter_null
`object.