Lumiera 0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
BranchCase< TYPES > Class Template Reference

#include "lib/branch-case.hpp"

Description

template<typename... TYPES>
class lib::BranchCase< TYPES >

A Sum Type to hold alternative results from a branched evaluation.

Template Parameters
TYPESsequence of all the types corresponding to all branches
Remarks
an instance is locked into a specific branch, as designated by the index in the type sequence. The payload object is placed inline, into an opaque buffer. You need to know the branch-number in order to re-access the (typed) content.

Definition at line 122 of file branch-case.hpp.

Public Types

template<size_t idx>
using SlotType = std::tuple_element_t< idx, tuple< TYPES... > >
 

Static Public Attributes

static constexpr auto TOP = sizeof...(TYPES) -1
 
static constexpr auto SIZ = _MaxBuf<TYPES...>::siz
 

Public Member Functions

template<class FUN >
auto accept (FUN &&visitor)
 Accept a visitor-functor (double dispatch).
 
 ~BranchCase ()
 
template<typename... INITS>
 BranchCase (size_t idx, INITS &&...inits)
 Standard constructor: select branch and provide initialiser.
 
 BranchCase (BranchCase const &o)
 
 BranchCase (BranchCase &&ro)
 
BranchCaseoperator= (BranchCase ref)
 
size_t selected () const
 
template<size_t idx>
SlotType< idx > & get ()
 re-access the value, using compile-time slot-index param.
 
auto getAny ()
 access the selected value of a homogeneous model.
 

Friends

void swap (BranchCase &o1, BranchCase &o2)
 

Protected Member Functions

 BranchCase ()=default
 
template<typename TX , typename... INITS>
TX & emplace (INITS &&...inits)
 
template<typename TX >
TX & access ()
 
template<size_t idx, class FUN >
auto selectBranch (FUN &&fun)
 apply generic functor to the currently selected branch
 

Protected Attributes

size_t branch_ {0}
 selector field to designate the chosen branch
 
std::byte buffer_ [SIZ]
 opaque inline storage buffer with suitable size and alignment
 

Constructor & Destructor Documentation

◆ BranchCase() [1/4]

template<typename... TYPES>
BranchCase ( )
protecteddefault

default-created state is invalid

◆ ~BranchCase()

template<typename... TYPES>
~BranchCase ( )
inline

Definition at line 183 of file branch-case.hpp.

References BranchCase< TYPES >::accept().

+ Here is the call graph for this function:

◆ BranchCase() [2/4]

template<typename... TYPES>
template<typename... INITS>
BranchCase ( size_t  idx,
INITS &&...  inits 
)
inline

Standard constructor: select branch and provide initialiser.

Definition at line 193 of file branch-case.hpp.

References BranchCase< TYPES >::accept().

+ Here is the call graph for this function:

◆ BranchCase() [3/4]

template<typename... TYPES>
BranchCase ( BranchCase< TYPES > const &  o)
inline

Definition at line 203 of file branch-case.hpp.

References BranchCase< TYPES >::branch_.

◆ BranchCase() [4/4]

template<typename... TYPES>
BranchCase ( BranchCase< TYPES > &&  ro)
inline

Definition at line 213 of file branch-case.hpp.

References BranchCase< TYPES >::branch_.

Member Typedef Documentation

◆ SlotType

template<typename... TYPES>
template<size_t idx>
using SlotType = std::tuple_element_t<idx, tuple<TYPES...> >

Definition at line 129 of file branch-case.hpp.

Member Function Documentation

◆ emplace()

template<typename... TYPES>
template<typename TX , typename... INITS>
TX & emplace ( INITS &&...  inits)
inlineprotected

Definition at line 145 of file branch-case.hpp.

References BranchCase< TYPES >::buffer_.

◆ access()

template<typename... TYPES>
template<typename TX >
TX & access ( )
inlineprotected

Definition at line 152 of file branch-case.hpp.

References BranchCase< TYPES >::buffer_.

◆ selectBranch()

template<typename... TYPES>
template<size_t idx, class FUN >
auto selectBranch ( FUN &&  fun)
inlineprotected

apply generic functor to the currently selected branch

Definition at line 160 of file branch-case.hpp.

References BranchCase< TYPES >::branch_, and BranchCase< TYPES >::selectBranch().

Referenced by BranchCase< TYPES >::selectBranch().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ accept()

template<typename... TYPES>
template<class FUN >
auto accept ( FUN &&  visitor)
inline

Accept a visitor-functor (double dispatch).

Note
the functor or lambda must be generic and indeed able to handle every possible branch type.
Warning
can only return single type for all branches.

Definition at line 178 of file branch-case.hpp.

Referenced by BranchCase< TYPES >::BranchCase(), BranchCase< TYPES >::~BranchCase(), and BranchCase< TYPES >::getAny().

+ Here is the caller graph for this function:

◆ operator=()

template<typename... TYPES>
BranchCase & operator= ( BranchCase< TYPES >  ref)
inline

Definition at line 244 of file branch-case.hpp.

References BranchCase< TYPES >::swap.

◆ selected()

template<typename... TYPES>
size_t selected ( ) const
inline

Definition at line 252 of file branch-case.hpp.

References BranchCase< TYPES >::branch_.

◆ get()

template<typename... TYPES>
template<size_t idx>
SlotType< idx > & get ( )
inline

re-access the value, using compile-time slot-index param.

Warning
must use the correct slot-idx (unchecked!)

Definition at line 262 of file branch-case.hpp.

Referenced by WrappedStandardExeBuilder::invokeOriginalBuilder().

+ Here is the caller graph for this function:

◆ getAny()

template<typename... TYPES>
auto getAny ( )
inline

access the selected value of a homogeneous model.

Warning
compiles only if all cases yield the same type

Definition at line 271 of file branch-case.hpp.

References BranchCase< TYPES >::accept().

+ Here is the call graph for this function:

Member Data Documentation

◆ TOP

template<typename... TYPES>
constexpr auto TOP = sizeof...(TYPES) -1
staticconstexpr

Definition at line 125 of file branch-case.hpp.

◆ SIZ

template<typename... TYPES>
constexpr auto SIZ = _MaxBuf<TYPES...>::siz
staticconstexpr

Definition at line 126 of file branch-case.hpp.

◆ branch_

template<typename... TYPES>
size_t branch_ {0}
protected

selector field to designate the chosen branch

Definition at line 135 of file branch-case.hpp.

Referenced by BranchCase< TYPES >::BranchCase(), BranchCase< TYPES >::BranchCase(), BranchCase< TYPES >::selectBranch(), and BranchCase< TYPES >::selected().

◆ buffer_

template<typename... TYPES>
std::byte buffer_[SIZ]
protected

opaque inline storage buffer with suitable size and alignment

Definition at line 140 of file branch-case.hpp.

Referenced by BranchCase< TYPES >::access(), and BranchCase< TYPES >::emplace().

Friends And Related Symbol Documentation

◆ swap

template<typename... TYPES>
void swap ( BranchCase< TYPES > &  o1,
BranchCase< TYPES > &  o2 
)
friend

Definition at line 223 of file branch-case.hpp.

Referenced by BranchCase< TYPES >::operator=().

+ Inheritance diagram for BranchCase< TYPES >:
+ Collaboration diagram for BranchCase< TYPES >:

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