Support Class Library
A set of tools providing classes and utility
|
Alternative type that stores one or the other. More...
#include "Either.h"
Classes | |
struct | lhs_tag |
Tag used to construct the LHS member (in case both are convertible types) More... | |
struct | payload_t |
Payload type that encapsulates both alternatives. More... | |
struct | rhs_tag |
Tag used to construct the RHS member (in case both are convertible types) More... | |
Public Types | |
using | left_type = Lhs |
The type of the left alternative. More... | |
using | right_type = Rhs |
The type of the right alternative. More... | |
Public Member Functions | |
Either ()=delete | |
template<class = scl::tools::meta ::void_t< scl::tools::meta ::enable_if_t<is_copyable()> >> | |
Either (const Either &other) | |
template<class = scl::tools::meta ::void_t< scl::tools::meta ::enable_if_t<is_copyable()> >> | |
Either & | operator= (const Either &other) |
template<class = scl::tools::meta ::void_t< scl::tools::meta ::enable_if_t<is_movable()> >> | |
Either (Either &&other) noexcept | |
template<class = scl::tools::meta ::void_t< scl::tools::meta ::enable_if_t<is_movable()> >> | |
Either & | operator= (Either &&other) noexcept |
bool | hasLeft () const |
Determines whether or not LHS is the active alternative. More... | |
bool | hasRight () const |
Determines whether or not RHS is the active alternative. More... | |
const Lhs & | getLeft () const |
Attempts to get the LHS value. More... | |
const Rhs & | getRight () const |
Attempts to get the RHS value. More... | |
template<class LeftVisitor , class RightVisitor > | |
const Either & | visit (LeftVisitor visitLeft, RightVisitor visitRight) const |
Visit this Either. More... | |
template<class LeftVisitor > | |
const Either & | doIfLeft (LeftVisitor visitLeft) const |
Execute a callback if LHS is the active alternative. More... | |
template<class RightVisitor > | |
const Either & | doIfRight (RightVisitor visitRight) const |
Execute a callback if RHS is the active alternative. More... | |
template<class NewLhs , class Mapper > | |
Either< NewLhs, Rhs > | mapLeftTo (Mapper mapper) const |
Maps the LHS if there's any. More... | |
template<class NewRhs , class Mapper > | |
Either< Lhs, NewRhs > | mapRightTo (Mapper mapper) const |
Maps the RHS if there's any. More... | |
template<class NewLhs , class NewRhs , class MapperLeft , class MapperRight > | |
Either< NewLhs, NewRhs > | mapTo (MapperLeft mapLeft, MapperRight mapRight) const |
Maps both alternatives. More... | |
Lhs | leftOr (const Lhs &defaultValue) const |
Tries to get the LHS value and fallback to default if not. More... | |
Rhs | rightOr (const Rhs &defaultValue) const |
Tries to get the RHS value and fallback to default if not. More... | |
Static Public Member Functions | |
template<class L > | |
static Either | left (L &&lhs) |
Construct the LHS. More... | |
template<class L > | |
static Either | Left (L &&lhs) |
Alias for Either::left. More... | |
template<class... Args> | |
static Either | emplaceLeft (Args &&... args) |
Constructs a Lhs in place. More... | |
template<class... Args> | |
static Either | emplaceRight (Args &&... args) |
Constructs a Rhs in place. More... | |
template<class R > | |
static Either | right (R &&rhs) |
Construct the RHS. More... | |
template<class R > | |
static Either | Right (R &&rhs) |
Alias for Either::right. More... | |
Protected Member Functions | |
template<class = scl::tools::meta ::enable_if_t< scl::tools::meta ::is_movable<Lhs>() >> | |
Either (lhs_tag, Lhs &&lhs) | |
Construct the LHS alternative (rvalue) More... | |
template<class = scl::tools::meta ::enable_if_t< scl::tools::meta ::is_copyable<Lhs>() >> | |
Either (lhs_tag, const Lhs &lhs) | |
Construct the LHS alternative (lvalue) More... | |
template<class = scl::tools::meta ::void_t< scl::tools::meta ::enable_if_t< scl::tools::meta ::is_movable<Rhs>() >>> | |
Either (rhs_tag, Rhs &&rhs) | |
Construct the RHS alternative (rvalue) More... | |
template<class = scl::tools::meta ::void_t< scl::tools::meta ::enable_if_t< scl::tools::meta ::is_copyable<Rhs>() >>> | |
Either (rhs_tag, const Rhs &rhs) | |
Construct the RHS alternative (lvalue) More... | |
Static Protected Member Functions | |
static constexpr bool | is_copyable () |
static constexpr bool | is_movable () |
static void | leftVoidVisitor (const Lhs &lhs) |
Handy visitor that does nothing on the LHS. More... | |
static void | rightVoidVisitor (const Rhs &rhs) |
Handy visitor that does nothing on the RHS. More... | |
Protected Attributes | |
bool | lhs = false |
Determines whether or ot the LHS member is the current alternative. More... | |
payload_t | payload = {} |
Stores the actual alternative payload. More... | |
Alternative type that stores one or the other.
Lhs | being the left value type |
Rhs | being the right value type |
scl::utils::Either< Lhs, Rhs >::left_type |
scl::utils::Either< Lhs, Rhs >::right_type |
|
inlineprotected |
|
inlineprotected |
|
inlineprotected |
|
inlineprotected |
|
delete |
|
inline |
|
inlinenoexcept |
|
inline |
|
inline |
|
inlinestatic |
|
inlinestatic |
|
inline |
Attempts to get the LHS value.
exceptions::InvalidEitherAccess | if LHS is not the active alternative |
|
inline |
Attempts to get the RHS value.
exceptions::InvalidEitherAccess | if RHS is not the active alternative |
|
inline |
|
inline |
|
inlinestaticprotected |
|
inlinestaticprotected |
|
inlinestatic |
|
inlinestatic |
Alias for Either::left.
|
inline |
|
inlinestaticprotected |
|
inline |
|
inline |
|
inline |
Maps both alternatives.
NewLhs | being the new LHS value type |
NewRhs | being the new RHS value type |
MapperLeft | being Lhs -> NewLhs |
MapperRight | being Rhs -> NewRhs |
mapLeft | being the LHS mapper function |
mapRight | being the RHS mapper function |
|
inline |
|
inlinenoexcept |
|
inlinestatic |
|
inlinestatic |
Alias for Either::right.
|
inline |
|
inlinestaticprotected |
|
inline |
|
protected |
|
protected |