51 #ifndef LIB_VARIANT_O_H 52 #define LIB_VARIANT_O_H 79 template<
typename TYPES>
94 Buffer() : which_(TYPECNT) {}
107 template<
typename T,
class BASE, u
int idx>
111 put (T
const& toStore)
113 BASE::deleteCurrent();
115 T& storedObj = *
new(BASE::buffer_) T (toStore);
132 template<
class FUNCTOR>
135 typedef typename FUNCTOR::Ret Ret;
136 typedef Ret (Func)(
Buffer&);
138 Func* table_[TYPECNT];
142 for (uint i=0; i<TYPECNT; ++i)
148 trampoline (
Buffer& storage)
150 T& content =
reinterpret_cast<T&
> (storage.buffer_);
151 return FUNCTOR::access (content);
157 if (TYPECNT <= storage.which_)
158 return FUNCTOR::ifEmpty ();
161 Func&
access = *table_[storage.which_];
170 template<
class T,
class BASE, u
int i >
176 BASE::table_[i] = &BASE::template trampoline<T>;
188 template<
class FUNCTOR>
189 static typename FUNCTOR::Ret
197 static Accessor select_case;
198 return select_case.invoke(buf);
207 static void access (T& elem) { elem.~T(); }
209 static void ifEmpty () { }
214 template<
typename TYPES>
218 access<Deleter>(*this);
250 template<
typename TYPES
251 ,
template<
typename>
class Access
267 void reset () { holder_.deleteCurrent();}
275 template<
typename SRC>
279 if (src) holder_.put (src);
291 template<
typename TAR>
295 typedef Access<TAR> Extractor;
296 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...