_num | The number of the types which can be stored in the variant type. | |
_TypeMap | This class describes the types of the Variant. The _TypeMap::Map<index>::Type should be a valid type for each index in the range {0, 1, ..., _num - 1}. The VariantTypeMap is helper class to define such type mappings up to 10 types. |
typedef Variant<3, VariantTypeMap<int, std::string, double> > MyVariant; MyVariant var; var.set<0>(12); std::cout << var.get<0>() << std::endl; var.set<1>("alpha"); std::cout << var.get<1>() << std::endl; var.set<2>(0.75); std::cout << var.get<2>() << std::endl;
The result of course:
12 alpha 0.75
#include <lemon/bits/variant.h>
Public Member Functions | |
Variant () | |
Constructor. | |
Variant (const Variant &variant) | |
Copy constructor. | |
Variant & | operator= (const Variant &variant) |
Assign operator. | |
~Variant () | |
Destrcutor. | |
template<int _idx> | |
Variant & | set () |
Set to the default value of the type with _idx index. | |
template<int _idx> | |
Variant & | set (const typename _TypeMap::template Map< _idx >::Type &init) |
Set to the given value of the type with _idx index. | |
template<int _idx> | |
const TypeMap::template Map < _idx >::Type & | get () const |
template<int _idx> | |
_TypeMap::template Map< _idx > ::Type & | get () |
int | state () const |
Variant | ( | ) | [inline] |
This constructor initalizes to the default value of the type
with 0 index.
~Variant | ( | ) | [inline] |
Destructor
Variant& set | ( | ) | [inline] |
This function sets the variant to the default value of the type with _idx
index.
Variant& set | ( | const typename _TypeMap::template Map< _idx >::Type & | init | ) | [inline] |
This function sets the variant to the given value of the type with _idx
index.
const TypeMap::template Map<_idx>::Type& get | ( | ) | const [inline] |
Gets the current value of the type with _idx
index.
_TypeMap::template Map<_idx>::Type& get | ( | ) | [inline] |
Gets the current value of the type with _idx
index.
int state | ( | ) | const [inline] |
Returns the current state of the variant.