Represents a concrete instance of a run-time specified type from a set of typesA concept is typically modeled by a collection of different types.
More...
template<typename Types>
class boost::gil::variant< Types >
Represents a concrete instance of a run-time specified type from a set of types
A concept is typically modeled by a collection of different types.
They may be instantiations of a templated type with different template parameters or even completely unrelated types.
We call the type with which the concept is instantiated in a given place in the code "the concrete type". The concrete type must be chosen at compile time, which sometimes is a severe limitation. Consider, for example, having an image concept modeled by an image class templated over the color space. It would be difficult to write a function that reads an image from file preserving its native color space, since the type of the return value is only available at run time. It would be difficult to store images of different color spaces in the same container or apply operations on them uniformly.
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