Honeycomb  0.1
Component-Model Framework
Classes | Public Member Functions | Friends | List of all members
honey::variant< Types > Class Template Reference

Multi-typed value. A variant is a value of any type from a fixed set of bounded types, the active bounded type may be changed dynamically. More...

#include <Variant.h>

Inheritance diagram for honey::variant< Types >:
Inheritance graph
[legend]
Collaboration diagram for honey::variant< Types >:
Collaboration graph
[legend]

Classes

struct  size_
 Get number of bounded types at compile-time. More...
 
struct  Type
 Get bounded type for id. More...
 

Public Member Functions

 variant ()
 First default constructible bounded type is set as the value. More...
 
template<class T >
 variant (T &&val)
 Attempts to copy/move construct any bounded type, otherwise first bounded type constructible with val is set as the value. More...
 
template<class... Args>
 variant (Args &&...args)
 First bounded type constructible with args is set as the value. More...
 
 variant (const variant &rhs)
 
 variant (variant &rhs)
 
 variant (variant &&rhs)
 
 ~variant ()
 
template<class T >
void bind (T &&val)
 Bind reference to object. First bounded reference type bindable to rhs is set as the value. More...
 
template<class T >
variantoperator= (T &&val)
 Attempts to copy/move-assign to any bounded type, otherwise first bounded type assignable to val is set as the value. More...
 
variantoperator= (const variant &rhs)
 
variantoperator= (variant &rhs)
 
variantoperator= (variant &&rhs)
 
szt size () const
 Get number of bounded types. More...
 
szt type () const
 Get active bounded type id, range [0, size) More...
 
template<class T >
T & get ()
 Get variant value as type. Throws VariantError if the active bounded type is not convertible to the requested type. More...
 
template<class T >
const T & get () const
 
template<class R , class Func , class... Args>
visit (Func &&f, Args &&...args)
 Visit stored value using functor. Calls functor(stored_value, args...) if such a call is valid and returns the result. More...
 
template<class R , class Func , class... Args>
visit (Func &&f, Args &&...args) const
 
template<class Func , class... Args>
void visit (Func &&f, Args &&...args)
 Visit for void result type. Does nothing (no throw) if the visitor does not accept the active bounded type. More...
 
template<class Func , class... Args>
void visit (Func &&f, Args &&...args) const
 

Friends

template<class , szt , class... >
class priv::variant
 
ostream & operator<< (ostream &os, const variant &rhs)
 

Detailed Description

template<class... Types>
class honey::variant< Types >

Multi-typed value. A variant is a value of any type from a fixed set of bounded types, the active bounded type may be changed dynamically.

Supports const/ref bounded types. A ref must be bound before it can be used, either construct with an object ref or call bind(). All assignments operate on the bound object.

A variant is implicitly convertible to any of its bounded types. Implicit conversion throws VariantError if the active bounded type is not convertible to the requested type.

Constructor & Destructor Documentation

template<class... Types>
honey::variant< Types >::variant ( )
inline

First default constructible bounded type is set as the value.

template<class... Types>
template<class T >
honey::variant< Types >::variant ( T &&  val)
inline

Attempts to copy/move construct any bounded type, otherwise first bounded type constructible with val is set as the value.

Fails at compile-time if no bounded types are constructible with val.

template<class... Types>
template<class... Args>
honey::variant< Types >::variant ( Args &&...  args)
inline

First bounded type constructible with args is set as the value.

template<class... Types>
honey::variant< Types >::variant ( const variant< Types > &  rhs)
inline
template<class... Types>
honey::variant< Types >::variant ( variant< Types > &  rhs)
inline
template<class... Types>
honey::variant< Types >::variant ( variant< Types > &&  rhs)
inline
template<class... Types>
honey::variant< Types >::~variant ( )
inline

Member Function Documentation

template<class... Types>
template<class T >
void honey::variant< Types >::bind ( T &&  val)
inline

Bind reference to object. First bounded reference type bindable to rhs is set as the value.

A bounded reference type is bindable to T if T* is convertible to BoundedType*.

template<class... Types>
template<class T >
T& honey::variant< Types >::get ( )
inline

Get variant value as type. Throws VariantError if the active bounded type is not convertible to the requested type.

template<class... Types>
template<class T >
const T& honey::variant< Types >::get ( ) const
inline
template<class... Types>
template<class T >
variant& honey::variant< Types >::operator= ( T &&  val)
inline

Attempts to copy/move-assign to any bounded type, otherwise first bounded type assignable to val is set as the value.

For a bounded type to be assignable to val it must also be constructible with val, this is necessary for changing the active bounded type. Fails at compile-time if no bounded types are assignable to val.

Bounded reference types must be bound to an object before being assigned, this is asserted at runtime.

template<class... Types>
variant& honey::variant< Types >::operator= ( const variant< Types > &  rhs)
inline
template<class... Types>
variant& honey::variant< Types >::operator= ( variant< Types > &  rhs)
inline
template<class... Types>
variant& honey::variant< Types >::operator= ( variant< Types > &&  rhs)
inline
template<class... Types>
szt honey::variant< Types >::size ( ) const
inline

Get number of bounded types.

template<class... Types>
szt honey::variant< Types >::type ( ) const
inline

Get active bounded type id, range [0, size)

template<class... Types>
template<class R , class Func , class... Args>
R honey::variant< Types >::visit ( Func &&  f,
Args &&...  args 
)
inline

Visit stored value using functor. Calls functor(stored_value, args...) if such a call is valid and returns the result.

Throws VariantError if the visitor does not accept the active bounded type.

template<class... Types>
template<class R , class Func , class... Args>
R honey::variant< Types >::visit ( Func &&  f,
Args &&...  args 
) const
inline
template<class... Types>
template<class Func , class... Args>
void honey::variant< Types >::visit ( Func &&  f,
Args &&...  args 
)
inline

Visit for void result type. Does nothing (no throw) if the visitor does not accept the active bounded type.

template<class... Types>
template<class Func , class... Args>
void honey::variant< Types >::visit ( Func &&  f,
Args &&...  args 
) const
inline

Friends And Related Function Documentation

template<class... Types>
ostream& operator<< ( ostream &  os,
const variant< Types > &  rhs 
)
friend
template<class... Types>
template<class , szt , class... >
friend class priv::variant
friend

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