42 #ifndef LIB_VARIANT_O_H 43 #define LIB_VARIANT_O_H 70 template<
typename TYPES>
85 Buffer() : which_(TYPECNT) {}
98 template<
typename T,
class BASE, u
int idx>
102 put (T
const& toStore)
104 BASE::deleteCurrent();
106 T& storedObj = *
new(BASE::buffer_) T (toStore);
123 template<
class FUNCTOR>
126 typedef typename FUNCTOR::Ret Ret;
127 typedef Ret (Func)(
Buffer&);
129 Func* table_[TYPECNT];
133 for (uint i=0; i<TYPECNT; ++i)
139 trampoline (
Buffer& storage)
141 T& content =
reinterpret_cast<T&
> (storage.buffer_);
142 return FUNCTOR::access (content);
148 if (TYPECNT <= storage.which_)
149 return FUNCTOR::ifEmpty ();
152 Func&
access = *table_[storage.which_];
161 template<
class T,
class BASE, u
int i >
167 BASE::table_[i] = &BASE::template trampoline<T>;
179 template<
class FUNCTOR>
180 static typename FUNCTOR::Ret
188 static Accessor select_case;
189 return select_case.invoke(buf);
198 static void access (T& elem) { elem.~T(); }
200 static void ifEmpty () { }
205 template<
typename TYPES>
209 access<Deleter>(*this);
241 template<
typename TYPES
242 ,
template<
typename>
class Access
258 void reset () { holder_.deleteCurrent();}
266 template<
typename SRC>
270 if (src) holder_.put (src);
282 template<
typename TAR>
286 typedef Access<TAR> Extractor;
287 return Holder::template access<Extractor> (this->holder_);
Holder::Storage holder_
storage: buffer holding either an "empty" marker, or an instance of one of the configured payload typ...
Any copy and copy construction prohibited.
Helpers for working with lib::meta::Types (i.e.
Metaprogramming: simple helpers for working with lists-of-types.
Implementation namespace for support and library code.
Storage to hold the actual value.
initialise the dispatcher (trampoline) for the case of accessing type T
provide a dispatcher table based visitation mechanism
Mix-Ins to allow or prohibit various degrees of copying and cloning.
static FUNCTOR::Ret access(Buffer &buf)
access the variant's inline buffer, using the configured access functor.
internal helper used to build a variant storage wrapper.
A variant wrapper (typesafe union) capable of holding a value of any of a bounded collection of types...