ConceptsBoundedTypeThe requirements on a bounded type
are as follows:CopyConstructible [20.1.3].Destructor upholds the no-throw exception-safety
guarantee.Complete at the point of variant template instantiation. (See
boost::incomplete<T> wrapper for
a solution to handling incomplete types.)Every type specified as a template argument to
variant must at minimum fulfill the
above requirements. In addition, certain features of variant
are available only if its bounded types meet the requirements of these
following additional concepts:Assignable:
variant is itself Assignable if and
only if every one of its bounded types meets the requirements of the
concept. (Note that top-level const-qualified types do
not meet these requirements.)DefaultConstructible:
variant is itself
DefaultConstructible if and only if its first
bounded type (i.e., T1) meets the requirements of the
concept.OutputStreamable:
variant is itself OutputStreamable
if and only if every one of its bounded types meets the requirements
of the concept.StaticVisitorThe requirements on a static
visitor of a type T are as follows:Must allow invocation as a function by overloading
operator(), unambiguously accepting any value of type
T.Must expose inner type result_type. (See
boost::visitor_ptr for a
solution to using functions as visitors.)If result_type is not void, then
each operation of the function object must return a value implicitly
convertible to result_type.ExamplesThe following class satisfies the requirements of a static visitor
of several types (i.e., explicitly: int and
std::string; or, e.g., implicitly: short and
const char *; etc.):class my_visitor
: public boost::static_visitor<int>
{
public:
int operator()(int i)
{
return i * 2;
}
int operator()(const std::string& s)
{
return s.length();
}
};Another example is the following class, whose function-call
operator is a member template, allowing it to operate on values of many
types. Thus, the following class is a visitor of any type that supports
streaming output (e.g., int, double,
std::string, etc.):class printer
: public boost::static_visitor<>
{
template <typename T>
void operator()(const T& t)
{
std::cout << t << std::endl;
}
};AssignableSee
external
documentation for this concept.DefaultConstructibleSee
external
documentation for this concept.OutputStreamableThe requirements on an output
streamable type T are as follows:For any object t of type T,
std::cout << t must be a valid
expression.