Variant
Header:
"boost/variant.hpp"
This contains all of the Variant library through a single header file.
"boost/variant/variant_fwd.hpp"
contains forward declarations of the
variant
class templates.
"boost/variant/variant.hpp"
contains the definitions for the
variant
class templates.
"boost/variant/apply_visitor.hpp"
contains the functionality for applying
visitors
to
variant
s.
"boost/variant/get.hpp"
contains the template function
get
.
"boost/variant/bad_visit.hpp"
contains the definition for the exception class
bad_visit
.
"boost/variant/static_visitor.hpp"
contains the definition for the
visitor
class template.
The following partial synopsis covers the most important
members
of the
variant
class template. Other functionality, such as the visitation mechanism, direct
typesafe
value retrieval, and advanced features such as creating the set of types through type sequences, are described in the "Usage" section.
namespace boost {
template <typename T1,typename T2=unspecified, ...,
typename TN=unspecified>
class variant {
public:
variant();
variant(const variant& other);
template <typename T> variant(const T& operand);
template <typename U1, typename U2, ..., typename UN>
variant(const variant<U1, U2, ..., UN>& operand);
~variant();
template <typename T> variant& operator=(const T& rhs);
int which() const;
bool empty() const;
const std::type_info& type() const;
bool operator==(const variant& rhs) const;
bool operator<(const variant& rhs) const;
};
}
Members
variant();
This constructor default constructs the first type of the set of types for the
variant
. This means that the first type used when declaring the
variant
type must be default constructible, or else the
variant
type itself cannot be default
constructed
. This constructor propagates any exceptions thrown from the first type's constructor.
variant(const variant& other);
The copy constructor copies the current value of
other
, propagating any exceptions thrown from
other
's current type's copy constructor.
template <typename T> variant(const T& operand);
This constructor creates a new
variant
from
operand
. The operand, of type
T
, must be unambiguously
convertible
to one of the set of bound types. Exceptions thrown when copying or converting the operand are propagated.
template <typename U1,typename U2,...,typename UN>
variant(const variant<U1,U2,...,UN>& operand);
This constructor allows construction from another
variant
type, where for each of the types
U1
,
U2
…
UN
, there exists an unambiguous conversion to
T1
,
T2
…
TN
(the set of types of the variant being constructed). Exceptions thrown when copying or converting the operand are propagated.
~variant();
Destroys the variant, and calls the destructor for the active value. Note that for pointer types, the destructor is not called (destroying the pointer is a no-op). This destructor never throws.
template <typename T> variant& operator=(const T& rhs);
This operator discards the current value and
assigns
the value
rhs
. The type
T
must be unambiguously convertible to one of the bound types in the
variant
. If
T
is the type of the current value in the
variant
,
rhs
is copy assigned to the current value; any exceptions thrown by
T
's copy assignment operator, if any, will propagate. If the
variant
's current value's type is not
T
, the current value is
replaced
by one created by the (copy) constructor of the type, corresponding to
T
, selected from the set of bound types. Any exceptions thrown by that constructor will propagate. This function may also throw
bad_alloc
.
int which() const;
Returns the
zero-based
index, in the set of bounded types, of the current value's type. This function never throws.
bool empty() const;
This function always returns
false
, because a
variant
is never empty. This function exists to allow generic code to treat
variant
s and
boost::any
s uniformly. This function never throws.
const std::type_info& type() const;
Returns the
type_info
for the current value. This function never throws.
bool operator==(const variant& rhs) const;
Returns
true
if
*this
and
rhs
are equal, which means that
which()==rhs.which()
and the current value of
*this
and
rhs
are equal according to the equality operator of the current value's type. This necessitates that all of the bounded types be
EqualityComparable
. Any exceptions thrown by
operator==
of the current value's type are propagated.
bool operator<(const variant& rhs) const;
The less than comparison returns
which()<rhs.which()
or if the indices are equal, it returns the result of calling
operator<
on the current value of
*this
and
rhs
. Any exceptions thrown by
operator<
of the current value's type are propagated.
|