LeechCraft  0.6.70-15082-g543737046d
Modular cross-platform feature rich live environment.
LC::Util::EitherCont< LeftSig, RightSig > Class Template Reference

A peir of two functions, typically a continuation and an error handler. More...

#include "eithercont.h"

Public Member Functions

 EitherCont ()=default
 Default-constructs the continuation with uninitialized functions. More...
 
template<typename L , typename R >
 EitherCont (const L &l, const R &r)
 Sets the left and right functions to l and r. More...
 
 operator bool () const
 Checks if both functions are initialized. More...
 
template<typename... Args>
auto Left (Args &&... args) const
 Invoke the left function and return its result. More...
 
template<typename... Args>
auto Right (Args &&... args) const
 Invoke the right function and return its result. More...
 

Detailed Description

template<typename LeftSig, typename RightSig>
class LC::Util::EitherCont< LeftSig, RightSig >

A peir of two functions, typically a continuation and an error handler.

Inspired by Haskell's Data.Either, the functions contained in EitherCont are called left and right respectively.

The common convention is to store the "normal" continuation in the right function, while the left one stores the error handler.

Template Parameters
LeftSigThe signature of the left function.
RightSigThe signature of the right function.

Definition at line 42 of file eithercont.h.

Constructor & Destructor Documentation

◆ EitherCont() [1/2]

template<typename LeftSig , typename RightSig >
LC::Util::EitherCont< LeftSig, RightSig >::EitherCont ( )
default

Default-constructs the continuation with uninitialized functions.

◆ EitherCont() [2/2]

template<typename LeftSig , typename RightSig >
template<typename L , typename R >
LC::Util::EitherCont< LeftSig, RightSig >::EitherCont ( const L &  l,
const R &  r 
)
inline

Sets the left and right functions to l and r.

Template Parameters
LThe type of the left functor which should be used to initialize the left function (must be convertible to LeftSig).
RThe type of the right functor which should be used to initialize the left function (must be convertible to LeftSig).

Definition at line 70 of file eithercont.h.

Member Function Documentation

◆ Left()

template<typename LeftSig , typename RightSig >
template<typename... Args>
auto LC::Util::EitherCont< LeftSig, RightSig >::Left ( Args &&...  args) const
inline

Invoke the left function and return its result.

Invokes the left function forwarding args of type Args (which may be different from the types in LeftSig, but convertible to them), and returns its result.

Parameters
[in]argsThe arguments to forward to the left function.
Returns
The result of invoking the left function with args.
Template Parameters
ArgsThe types of arguments to pass to the left function.
See also
Right()

Definition at line 102 of file eithercont.h.

◆ operator bool()

template<typename LeftSig , typename RightSig >
LC::Util::EitherCont< LeftSig, RightSig >::operator bool ( ) const
inlineexplicit

Checks if both functions are initialized.

Calling any function on an object for which this function returns false leads to undefined behavior.

Returns
Whether both function are initialized.

Definition at line 83 of file eithercont.h.

◆ Right()

template<typename LeftSig , typename RightSig >
template<typename... Args>
auto LC::Util::EitherCont< LeftSig, RightSig >::Right ( Args &&...  args) const
inline

Invoke the right function and return its result.

Invokes the right function forwarding args of type Args (which may be different from the types in RightSig, but convertible to them), and returns its result.

Parameters
[in]argsThe arguments to forward to the right function.
Returns
The result of invoking the right function with args.
Template Parameters
ArgsThe types of arguments to pass to the right function.
See also
Left()

Definition at line 121 of file eithercont.h.


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