Information
MediaSupport
RSSOther Adobe ProjectsOther Resources |
variant< TYPES > Class Template ReferenceRepresents a concrete instance of a run-time specified type from a set of types |
Public Types | |
typedef TYPES | types_t |
Public Member Functions | |
template<typename T> | |
T & | _dynamic_cast () |
template<typename T> | |
const T & | _dynamic_cast () const |
template<typename T> | |
void | move_in (T &obj) |
variant & | operator= (const variant &v) |
template<typename T> | |
variant & | operator= (const T &obj) |
variant (const variant &v) | |
template<typename T> | |
variant (T &obj, bool do_swap) | |
template<typename T> | |
variant (const T &obj) | |
variant () | |
virtual | ~variant () |
Static Public Member Functions | |
template<typename T> | |
static bool | has_type () |
Friends | |
template<typename TYPES1, typename TYPES2, typename BINARY_OP> | |
BINARY_OP::result_type | apply_operation (const variant< TYPES1 > &arg1, const variant< TYPES2 > &arg2, BINARY_OP op) |
template<typename TYPES2, typename UNARY_OP> | |
UNARY_OP::result_type | apply_operation (const variant< TYPES2 > &var, UNARY_OP op) |
template<typename TYPES2, typename UNARY_OP> | |
UNARY_OP::result_type | apply_operation (variant< TYPES2 > &var, UNARY_OP op) |
template<typename TS> | |
bool | operator!= (const variant< TS > &x, const variant< TS > &y) |
template<typename TS> | |
bool | operator== (const variant< TS > &x, const variant< TS > &y) |
template<typename CS> | |
void | swap (variant< CS > &x, variant< CS > &y) |
Classes | |
struct | base_t |
The variant class addresses this deficiency. It allows for run-time instantiation of a class from a given set of allowed classes specified at compile time. For example, the set of allowed classes may include 8-bit and 16-bit RGB and CMYK images. Such a variant can be constructed with rgb8_image_t and then assigned a cmyk16_image_t.
The variant has a templated constructor, which allows us to construct it with any concrete type instantiation. It can also perform a generic operation on the concrete type via a call to apply_operation. The operation must be provided as a function object whose application operator has a single parameter which can be instantiated with any of the allowed types of the variant.
variant breaks down the instantiated type into a non-templated underlying base type and a unique instantiation type identifier. In the most common implementation the concrete instantiation in stored 'in-place' - in 'bits_t'. bits_t contains sufficient space to fit the largest of the instantiated objects.
GIL's variant is similar to boost::variant in spirit (hence we borrow the name from there) but it differs in several ways from the current boost implementation. Most notably, it does not take a variable number of template parameters but a single parameter defining the type enumeration. As such it can be used more effectively in generic code.
The TYPES parameter specifies the set of allowable types. It models MPL Random Access Container
Definition at line 77 of file variant.hpp.