Lumiera  0.pre.03
»edit your freedom«
Variant< TYPES > Class Template Reference

#include "lib/variant.hpp"

Description

template<typename TYPES>
class lib::Variant< TYPES >

Typesafe union record.

A Variant element may carry an embedded value of any of the predefined types. The type may not be rebound: It must be created holding some value and each instance is fixed to the specific type used at construction time. Yet within the same type, variant elements are copyable and assignable. The embedded type is erased on the signature, but knowledge about the actual type is retained, encoded into the embedded VTable. Thus, any access to the variant's value requires knowledge of the type in question, but type mismatch will provoke an exception at runtime. Generic access is possible using a visitor.

Warning
not threadsafe
Todo:
we need to define all copy operations explicitly, due to the templated one-arg ctor to wrap the actual values. There might be a generic solution for that ////////////////////////TICKET #963 Forwarding shadows copy operations – generic solution?? But – Beware of unverifiable generic solutions!

Definition at line 224 of file variant.hpp.

Public Types

enum  {
  SIZ = meta::maxSize<typename TYPES::List>::value,
  ALIGN = meta::maxAlign<typename TYPES::List>::value
}
 
template<template< class > class _P_>
using FirstMatching = variant::FirstMatchingType< TYPES, _P_ >
 Metafunction to pick the first of the variant's types, which satisfies the given trait or predicate template. More...
 
template<typename RET >
using VisitorConstFunc = typename variant::VFunc< RET >::template VisitorInterface< meta::ConstAll< typename TYPES::List > >
 
template<typename RET >
using VisitorFunc = typename variant::VFunc< RET >::template VisitorInterface< TYPES >
 

Public Member Functions

template<typename X >
 Variant (X &&x)
 
 Variant (Variant &ref)
 
 Variant (Variant const &ref)
 
 Variant (Variant &&rref)
 
void accept (Visitor &visitor)
 
bool accept (Predicate &visitor) const
 
string accept (Renderer &visitor) const
 
template<typename X >
X & get ()
 
template<typename X >
X const & get () const
 
 operator string () const
 diagnostic helper
 
template<typename X >
Variantoperator= (X x)
 
Variantoperator= (Variant &ovar)
 
Variantoperator= (Variant const &ovar)
 
Variantoperator= (Variant &&rvar)
 

Classes

struct  Buff
 concrete inner capsule specialised for a given type More...
 
struct  Buffer
 Inner capsule managing the contained object (interface) More...
 
class  Predicate
 
class  Renderer
 
class  Visitor
 to be implemented by the client for visitation More...
 

Protected Member Functions

template<typename X >
Buff< X > & buff ()
 
Bufferbuffer ()
 
Buffer const & buffer () const
 
template<typename X >
X * maybeGet ()
 

Private Types

enum  { BUFFSIZE = sizeof(Buffer) }
 

Private Attributes

char storage_ [BUFFSIZE]
 embedded buffer actually holding the concrete Buff object, which in turn holds and manages the target object. More...
 

Member Typedef Documentation

◆ FirstMatching

Metafunction to pick the first of the variant's types, which satisfies the given trait or predicate template.

Note
result is the embedded typedef FirstMatching<P>::Type

Definition at line 268 of file variant.hpp.

Member Function Documentation

◆ maybeGet()

X* maybeGet ( )
inlineprotected

for derived classes to implement custom access logic

Definition at line 437 of file variant.hpp.

Member Data Documentation

◆ storage_

char storage_[BUFFSIZE]
private

embedded buffer actually holding the concrete Buff object, which in turn holds and manages the target object.

Note
Invariant: always contains a valid Buffer subclass

Definition at line 408 of file variant.hpp.

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

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