| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325 |
- <html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Class template variant</title><link rel="stylesheet" href="reference.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.61.3"><link rel="home" href="index.html" title="The Boost C++ Libraries"><link rel="up" href="variant.reference.html#header.boost.variant.variant.hpp" title="Header <boost/variant/variant.hpp>"><link rel="previous" href="BOOST_VARIANT_NO_FULL_RECURSIVE_VARIANT_SUPPORT.html" title="Macro BOOST_VARIANT_NO_FULL_RECURSIVE_VARIANT_SUPPORT"><link rel="next" href="id2518553-bb.html" title="Function template swap"><link rel="chapter" href="libraries.html" title="The Boost C++ Libraries"><link rel="chapter" href="any.html" title="Boost.Any"><link rel="refentry" href="class.boost.bad_any_cast.html" title="Class bad_any_cast"><link rel="refentry" href="class.boost.any.html" title="Class any"><link rel="refentry" href="id2383300-bb.html" title="Function any_cast"><link rel="chapter" href="array.html" title="Boost.Array"><link rel="refentry" href="class.boost.array.html" title="Class template array"><link rel="chapter" href="function.html" title="Boost.Function"><link rel="refentry" href="class.boost.bad_function_call.html" title="Class bad_function_call"><link rel="refentry" href="class.boost.function_base.html" title="Class function_base"><link rel="refentry" href="class.boost.functionN.html" title="Class template functionN"><link rel="refentry" href="class.boost.function.html" title="Class template function"><link rel="chapter" href="ref.html" title="Boost.Ref"><link rel="refentry" href="class.boost.reference_wrapper.html" title="Class template reference_wrapper"><link rel="refentry" href="class.boost.is_reference_wrapper.html" title="Class template is_reference_wrapper"><link rel="refentry" href="class.boost.unwrap_reference.html" title="Class template unwrap_reference"><link rel="chapter" href="signals.html" title="Boost.Signals"><link rel="refentry" href="class.boost.signalN.html" title="Class template signalN"><link rel="refentry" href="class.boost.signal.html" title="Class template signal"><link rel="refentry" href="class.boost.slot.html" title="Class template slot"><link rel="refentry" href="class.boost.signals.trackable.html" title="Class trackable"><link rel="refentry" href="class.boost.signals.connection.html" title="Class connection"><link rel="refentry" href="class.boost.signals.scoped_connection.html" title="Class scoped_connection"><link rel="refentry" href="id2532119-bb.html" title="Function template visit_each"><link rel="refentry" href="class.boost.last_value.html" title="Class template last_value"><link rel="refentry" href="id2354683-bb.html" title="Class last_value<void>"><link rel="chapter" href="variant.html" title="Boost.Variant"><link rel="refentry" href="BOOST_VARIANT_LIMIT_TYPES.html" title="Macro BOOST_VARIANT_LIMIT_TYPES"><link rel="refentry" href="BOOST_VARIANT_ENUM_PARAMS.html" title="Macro BOOST_VARIANT_ENUM_PARAMS"><link rel="refentry" href="BOOST_VARIANT_ENUM_SHIFTED_PARAMS.html" title="Macro BOOST_VARIANT_ENUM_SHIFTED_PARAMS"><link rel="refentry" href="BOOST_VARIANT_NO_REFERENCE_SUPPORT.html" title="Macro BOOST_VARIANT_NO_REFERENCE_SUPPORT"><link rel="refentry" href="BOOST_VARIANT_NO_TYPE_SEQUENCE_SUPPORT.html" title="Macro BOOST_VARIANT_NO_TYPE_SEQUENCE_SUPPORT"><link rel="refentry" href="BOOST_VARIANT_NO_FULL_RECURSIVE_VARIANT_SUPPORT.html" title="Macro BOOST_VARIANT_NO_FULL_RECURSIVE_VARIANT_SUPPORT"><link rel="refentry" href="class.boost.variant.html" title="Class template variant"><link rel="refentry" href="id2518553-bb.html" title="Function template swap"><link rel="refentry" href="id2524211-bb.html" title="Function template operator<<"><link rel="refentry" href="class.boost.make_variant_over.html" title="Class template make_variant_over"><link rel="refentry" href="class.boost.make_recursive_variant.html" title="Class template make_recursive_variant"><link rel="refentry" href="class.boost.make_recursive_variant_over.html" title="Class template make_recursive_variant_over"><link rel="refentry" href="class.boost.recursive_wrapper.html" title="Class template recursive_wrapper"><link rel="refentry" href="class.boost.is_recursive_wrapper.html" title="Class template is_recursive_wrapper"><link rel="refentry" href="class.boost.unwrap_recursive_wrapper.html" title="Class template unwrap_recursive_wrapper"><link rel="refentry" href="class.boost.apply_visitor_delayed_t.html" title="Class template apply_visitor_delayed_t"><link rel="refentry" href="id2557051-bb.html" title="Function apply_visitor"><link rel="refentry" href="class.boost.bad_get.html" title="Class bad_get"><link rel="refentry" href="id2493238-bb.html" title="Function get"><link rel="refentry" href="class.boost.bad_visit.html" title="Class bad_visit"><link rel="refentry" href="class.boost.static_visitor.html" title="Class template static_visitor"><link rel="refentry" href="class.boost.visitor_ptr_t.html" title="Class template visitor_ptr_t"><link rel="refentry" href="id2544445-bb.html" title="Function template visitor_ptr"><link rel="chapter" href="boostbook.html" title="The BoostBook Documentation Format"><link rel="refentry" href="boostbook.dtd.class-specialization.html" title="
- BoostBook element class-specialization"><link rel="refentry" href="boostbook.dtd.link-test.html" title="
- BoostBook element link-test"><link rel="refentry" href="boostbook.dtd.link-fail-test.html" title="
- BoostBook element link-fail-test"><link rel="refentry" href="boostbook.dtd.typedef.html" title="
- BoostBook element typedef"><link rel="refentry" href="boostbook.dtd.static-constant.html" title="
- BoostBook element static-constant"><link rel="refentry" href="boostbook.dtd.code.html" title="
- BoostBook element code"><link rel="refentry" href="boostbook.dtd.destructor.html" title="
- BoostBook element destructor"><link rel="refentry" href="boostbook.dtd.template-type-parameter.html" title="
- BoostBook element template-type-parameter"><link rel="refentry" href="boostbook.dtd.description.html" title="
- BoostBook element description"><link rel="refentry" href="boostbook.dtd.librarylist.html" title="
- BoostBook element librarylist"><link rel="refentry" href="boostbook.dtd.library-reference.html" title="
- BoostBook element library-reference"><link rel="refentry" href="boostbook.dtd.boostbook.html" title="
- BoostBook element boostbook"><link rel="refentry" href="boostbook.dtd.union.html" title="
- BoostBook element union"><link rel="refentry" href="boostbook.dtd.inherit.html" title="
- BoostBook element inherit"><link rel="refentry" href="boostbook.dtd.template-varargs.html" title="
- BoostBook element template-varargs"><link rel="refentry" href="boostbook.dtd.source.html" title="
- BoostBook element source"><link rel="refentry" href="boostbook.dtd.function.html" title="
- BoostBook element function"><link rel="refentry" href="boostbook.dtd.postconditions.html" title="
- BoostBook element postconditions"><link rel="refentry" href="boostbook.dtd.compile-test.html" title="
- BoostBook element compile-test"><link rel="refentry" href="boostbook.dtd.method.html" title="
- BoostBook element method"><link rel="refentry" href="boostbook.dtd.snippet.html" title="
- BoostBook element snippet"><link rel="refentry" href="boostbook.dtd.constructor.html" title="
- BoostBook element constructor"><link rel="refentry" href="boostbook.dtd.namespace.html" title="
- BoostBook element namespace"><link rel="refentry" href="boostbook.dtd.if-fails.html" title="
- BoostBook element if-fails"><link rel="refentry" href="boostbook.dtd.free-function-group.html" title="
- BoostBook element free-function-group"><link rel="refentry" href="boostbook.dtd.functionname.html" title="
- BoostBook element functionname"><link rel="refentry" href="boostbook.dtd.librarycategory.html" title="
- BoostBook element librarycategory"><link rel="refentry" href="boostbook.dtd.notes.html" title="
- BoostBook element notes"><link rel="refentry" href="boostbook.dtd.data-member.html" title="
- BoostBook element data-member"><link rel="refentry" href="boostbook.dtd.specialization.html" title="
- BoostBook element specialization"><link rel="refentry" href="boostbook.dtd.union-specialization.html" title="
- BoostBook element union-specialization"><link rel="refentry" href="boostbook.dtd.throws.html" title="
- BoostBook element throws"><link rel="refentry" href="boostbook.dtd.template-arg.html" title="
- BoostBook element template-arg"><link rel="refentry" href="boostbook.dtd.method-group.html" title="
- BoostBook element method-group"><link rel="refentry" href="boostbook.dtd.requirement.html" title="
- BoostBook element requirement"><link rel="refentry" href="boostbook.dtd.precondition.html" title="
- BoostBook element precondition"><link rel="refentry" href="boostbook.dtd.paramtype.html" title="
- BoostBook element paramtype"><link rel="refentry" href="boostbook.dtd.using-class.html" title="
- BoostBook element using-class"><link rel="refentry" href="boostbook.dtd.run-test.html" title="
- BoostBook element run-test"><link rel="refentry" href="boostbook.dtd.librarypurpose.html" title="
- BoostBook element librarypurpose"><link rel="refentry" href="boostbook.dtd.copy-assignment.html" title="
- BoostBook element copy-assignment"><link rel="refentry" href="boostbook.dtd.run-fail-test.html" title="
- BoostBook element run-fail-test"><link rel="refentry" href="boostbook.dtd.template.html" title="
- BoostBook element template"><link rel="refentry" href="boostbook.dtd.compile-fail-test.html" title="
- BoostBook element compile-fail-test"><link rel="refentry" href="boostbook.dtd.returns.html" title="
- BoostBook element returns"><link rel="refentry" href="boostbook.dtd.default.html" title="
- BoostBook element default"><link rel="refentry" href="boostbook.dtd.parameter.html" title="
- BoostBook element parameter"><link rel="refentry" href="boostbook.dtd.signature.html" title="
- BoostBook element signature"><link rel="refentry" href="boostbook.dtd.overloaded-function.html" title="
- BoostBook element overloaded-function"><link rel="refentry" href="boostbook.dtd.class.html" title="
- BoostBook element class"><link rel="refentry" href="boostbook.dtd.librarycategorydef.html" title="
- BoostBook element librarycategorydef"><link rel="refentry" href="boostbook.dtd.type.html" title="
- BoostBook element type"><link rel="refentry" href="boostbook.dtd.enumvalue.html" title="
- BoostBook element enumvalue"><link rel="refentry" href="boostbook.dtd.overloaded-method.html" title="
- BoostBook element overloaded-method"><link rel="refentry" href="boostbook.dtd.programlisting.html" title="
- BoostBook element programlisting"><link rel="refentry" href="boostbook.dtd.complexity.html" title="
- BoostBook element complexity"><link rel="refentry" href="boostbook.dtd.purpose.html" title="
- BoostBook element purpose"><link rel="refentry" href="boostbook.dtd.template-nontype-parameter.html" title="
- BoostBook element template-nontype-parameter"><link rel="refentry" href="boostbook.dtd.library.html" title="
- BoostBook element library"><link rel="refentry" href="boostbook.dtd.librarycategorylist.html" title="
- BoostBook element librarycategorylist"><link rel="refentry" href="boostbook.dtd.using-namespace.html" title="
- BoostBook element using-namespace"><link rel="refentry" href="boostbook.dtd.struct-specialization.html" title="
- BoostBook element struct-specialization"><link rel="refentry" href="boostbook.dtd.struct.html" title="
- BoostBook element struct"><link rel="refentry" href="boostbook.dtd.lib.html" title="
- BoostBook element lib"><link rel="refentry" href="boostbook.dtd.enum.html" title="
- BoostBook element enum"><link rel="refentry" href="boostbook.dtd.requires.html" title="
- BoostBook element requires"><link rel="refentry" href="boostbook.dtd.effects.html" title="
- BoostBook element effects"><link rel="refentry" href="boostbook.dtd.libraryname.html" title="
- BoostBook element libraryname"><link rel="refentry" href="boostbook.dtd.libraryinfo.html" title="
- BoostBook element libraryinfo"><link rel="refentry" href="boostbook.dtd.testsuite.html" title="
- BoostBook element testsuite"><link rel="refentry" href="boostbook.dtd.header.html" title="
- BoostBook element header"><link rel="refentry" href="boostbook.dtd.rationale.html" title="
- BoostBook element rationale"><link rel="refentry" href="Assignable.html" title="Concept Assignable"><link rel="refentry" href="InputIterator.html" title="Concept InputIterator"><link rel="refentry" href="OutputIterator.html" title="Concept OutputIterator"><link rel="refentry" href="ForwardIterator.html" title="Concept ForwardIterator"><link rel="refentry" href="BidirectionalIterator.html" title="Concept BidirectionalIterator"><link rel="refentry" href="RandomAccessIterator.html" title="Concept RandomAccessIterator"><link rel="refentry" href="DefaultConstructible.html" title="Concept DefaultConstructible"><link rel="refentry" href="CopyConstructible.html" title="Concept CopyConstructible"><link rel="refentry" href="EqualityComparable.html" title="Concept EqualityComparable"><link rel="refentry" href="LessThanComparable.html" title="Concept LessThanComparable"><link rel="refentry" href="SignedInteger.html" title="Concept SignedInteger"><link rel="section" href="class.boost.variant.html#id2531529" title="Description"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" border="1" cellpadding="2" bgcolor="#007F7F"><tr><td bgcolor="#FFFFFF"><img src="../../c++boost.gif" alt="c++boost.gif (8819 bytes)" width="277" height="86"></td><td><a href="../../index.htm"><font color="#FFFFFF" size="4" face="Arial">Home</font></a></td><td><a href="libraries.html"><font color="#FFFFFF" size="4" face="Arial">Libraries</font></a></td><td><a href="../../people/people.htm"><font color="#FFFFFF" size="4" face="Arial">People</font></a></td><td><a href="../../more/faq.htm"><font color="#FFFFFF" size="4" face="Arial">FAQ</font></a></td><td><a href="../../more/index.htm"><font color="#FFFFFF" size="4" face="Arial">More</font></a></td></tr></table><div class="refentry" lang="en"><a name="class.boost.variant"></a><div class="titlepage"><div></div><div></div></div><div class="refnamediv"><h2><span class="refentrytitle">Class template variant</span></h2><p>boost::variant — Safe, generic, stack-based discriminated union container.</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis"><span class="bold"><b>template</b></span><<span class="bold"><b>typename</b></span> T1, <span class="bold"><b>typename</b></span> T2 = <span class="emphasis"><em>unspecified</em></span>, ...,
- <span class="bold"><b>typename</b></span> TN = <span class="emphasis"><em>unspecified</em></span>>
- <span class="bold"><b>class</b></span> variant {
- <span class="bold"><b>public</b></span>:
- <span class="emphasis"><em>// types</em></span>
- <span class="bold"><b>typedef</b></span> <span class="emphasis"><em>unspecified</em></span> types;
- <span class="emphasis"><em>// <a href="class.boost.variant.html#class.boost.variantconstruct-copy-destruct">construct/copy/destruct</a></em></span>
- <a href="class.boost.variant.html#id2410771-bb">variant</a>();
- <a href="class.boost.variant.html#id2458124-bb">variant</a>(<span class="bold"><b>const</b></span> variant &);
- <span class="bold"><b>template</b></span><<span class="bold"><b>typename</b></span> T> <a href="class.boost.variant.html#id2375383-bb">variant</a>(T &);
- <span class="bold"><b>template</b></span><<span class="bold"><b>typename</b></span> T> <a href="class.boost.variant.html#id2485087-bb">variant</a>(<span class="bold"><b>const</b></span> T &);
- <span class="bold"><b>template</b></span><<span class="bold"><b>typename</b></span> U1, <span class="bold"><b>typename</b></span> U2, ..., <span class="bold"><b>typename</b></span> UN>
- <a href="class.boost.variant.html#id2516325-bb">variant</a>(variant<U1, U2, ..., UN> &);
- <span class="bold"><b>template</b></span><<span class="bold"><b>typename</b></span> U1, <span class="bold"><b>typename</b></span> U2, ..., <span class="bold"><b>typename</b></span> UN>
- <a href="class.boost.variant.html#id2355967-bb">variant</a>(<span class="bold"><b>const</b></span> variant<U1, U2, ..., UN> &);
- <a href="class.boost.variant.html#id2489745-bb">~variant</a>();
- <span class="emphasis"><em>// <a href="class.boost.variant.html#id2549864-bb">modifiers</a></em></span>
- <span class="type"><span class="bold"><b>void</b></span></span> <a href="class.boost.variant.html#id2514140-bb">swap</a>(variant &);
- <span class="type">variant &</span> <a href="class.boost.variant.html#id2509331-bb"><span class="bold"><b>operator</b></span>=</a>(<span class="bold"><b>const</b></span> variant &);
- <span class="bold"><b>template</b></span><<span class="bold"><b>typename</b></span> T> <span class="type">variant &</span> <a href="class.boost.variant.html#id2489594-bb"><span class="bold"><b>operator</b></span>=</a>(<span class="bold"><b>const</b></span> T &);
- <span class="emphasis"><em>// <a href="class.boost.variant.html#id2370110-bb">queries</a></em></span>
- <span class="type"><span class="bold"><b>int</b></span></span> <a href="class.boost.variant.html#id2466395-bb">which</a>() <span class="bold"><b>const</b></span>;
- <span class="type"><span class="bold"><b>bool</b></span></span> <a href="class.boost.variant.html#id2494720-bb">empty</a>() <span class="bold"><b>const</b></span>;
- <span class="type"><span class="bold"><b>const</b></span> std::type_info &</span> <a href="class.boost.variant.html#id2508948-bb">type</a>() <span class="bold"><b>const</b></span>;
- <span class="emphasis"><em>// <a href="class.boost.variant.html#id2450166-bb">relational</a></em></span>
- <span class="type"><span class="bold"><b>bool</b></span></span> <a href="class.boost.variant.html#id2492818-bb"><span class="bold"><b>operator</b></span>==</a>(<span class="bold"><b>const</b></span> variant &) <span class="bold"><b>const</b></span>;
- <span class="bold"><b>template</b></span><<span class="bold"><b>typename</b></span> U> <span class="type"><span class="bold"><b>void</b></span></span> <a href="class.boost.variant.html#id2495748-bb"><span class="bold"><b>operator</b></span>==</a>(<span class="bold"><b>const</b></span> U &) <span class="bold"><b>const</b></span>;
- <span class="type"><span class="bold"><b>bool</b></span></span> <a href="class.boost.variant.html#id2372301-bb"><span class="bold"><b>operator</b></span><</a>(<span class="bold"><b>const</b></span> variant &) <span class="bold"><b>const</b></span>;
- <span class="bold"><b>template</b></span><<span class="bold"><b>typename</b></span> U> <span class="type"><span class="bold"><b>void</b></span></span> <a href="class.boost.variant.html#id2433666-bb"><span class="bold"><b>operator</b></span><</a>(<span class="bold"><b>const</b></span> U &) <span class="bold"><b>const</b></span>;
- };</pre></div><div class="refsect1" lang="en"><h2>Description</h2><p>The <tt class="computeroutput">variant</tt> class template (inspired by Andrei
- Alexandrescu's class of the same name
- [<a href="variant.refs.html#variant.refs.ale01a">Ale01A</a>]) is an efficient,
- <a href="variant.tutorial.html#variant.tutorial.recursive" title="Recursive variant types">recursive-capable</a>,
- bounded discriminated union value type capable of containing any value
- type (either POD or non-POD). It supports construction from any type
- convertible to one of its bounded types or from a source
- <tt class="computeroutput">variant</tt> whose bounded types are each convertible to one
- of the destination <tt class="computeroutput">variant</tt>'s bounded types. As well,
- through <tt class="computeroutput"><a href="id2557051-bb.html" title="Function apply_visitor">apply_visitor</a></tt>,
- <tt class="computeroutput">variant</tt> supports compile-time checked, type-safe
- visitation; and through <tt class="computeroutput"><a href="id2493238-bb.html" title="Function get">get</a></tt>,
- <tt class="computeroutput">variant</tt> supports run-time checked, type-safe value
- retrieval.</p><p><span class="bold"><b>Notes</b></span>:</p><div class="itemizedlist"><ul type="disc"><li>The bounded types of the <tt class="computeroutput">variant</tt> are exposed
- via the nested typedef <tt class="computeroutput">types</tt>, which is an
- <a href="../../libs/mpl/index.html" target="_top">MPL</a>-compatible Sequence containing the
- set of types that must be handled by any
- <a href="variant.reference.html#variant.concepts.static-visitor" title="StaticVisitor">visitor</a> to
- the <tt class="computeroutput">variant</tt>.</li><li>All members of <tt class="computeroutput">variant</tt> satisfy at least the
- basic guarantee of exception-safety. That is, all operations on
- a <tt class="computeroutput">variant</tt> remain defined even after previous
- operations have failed.</li><li>Each type specified as a template argument to
- <tt class="computeroutput">variant</tt> must meet the requirements of the
- <span class="emphasis"><em><a href="variant.reference.html#variant.concepts.bounded-type" title="BoundedType">BoundedType</a></em></span>
- concept.</li><li>Each type specified as a template argument to
- <tt class="computeroutput">variant</tt> must be distinct after removal of qualifiers.
- Thus, for instance, both <tt class="computeroutput">variant<int, int></tt> and
- <tt class="computeroutput">variant<int, const int></tt> have undefined
- behavior.</li><li>Conforming implementations of <tt class="computeroutput">variant</tt> must
- allow at least ten types as template arguments. The exact number
- of allowed arguments is exposed by the preprocessor macro
- <tt class="computeroutput"><a href="BOOST_VARIANT_LIMIT_TYPES.html" title="Macro BOOST_VARIANT_LIMIT_TYPES">BOOST_VARIANT_LIMIT_TYPES</a></tt>.
- (See <tt class="computeroutput"><a href="class.boost.make_variant_over.html" title="Class template make_variant_over">make_variant_over</a></tt> for a
- means to specify the bounded types of a <tt class="computeroutput">variant</tt> by
- the elements of an <a href="../../libs/mpl/index.html" target="_top">MPL</a> or compatible
- Sequence, thus overcoming this limitation.)</li></ul></div><div class="refsect2" lang="en"><h3><a name="class.boost.variantconstruct-copy-destruct"></a><tt class="computeroutput">variant</tt> construct/copy/destruct</h3><div class="orderedlist"><ol type="1"><li><pre class="literallayout"><a name="id2410771-bb"></a>variant();</pre><p xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><b><span class="term">Requires</span></b>:
- The first bounded type of the <tt class="computeroutput">variant</tt> (i.e.,
- <tt class="computeroutput">T1</tt>) must fulfill the requirements of the
- <span class="emphasis"><em>DefaultConstructible</em></span> [20.1.4]
- concept.<br><b><span class="term">Postconditions</span></b>:
- Content of <tt class="computeroutput">*this</tt> is the default value of the
- first bounded type (i.e, <tt class="computeroutput">T1</tt>).<br><b><span class="term">Throws</span></b>:
- May fail with any exceptions arising from the default
- constructor of <tt class="computeroutput">T1</tt>.</p></li><li><pre class="literallayout"><a name="id2458124-bb"></a>variant(<span class="bold"><b>const</b></span> variant & other);</pre><p xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><b><span class="term">Postconditions</span></b>:
- Content of <tt class="computeroutput">*this</tt> is a copy of the content of
- <tt class="computeroutput">other</tt>.<br><b><span class="term">Throws</span></b>:
- May fail with any exceptions arising from the
- copy constructor of <tt class="computeroutput">other</tt>'s contained type.</p></li><li><pre class="literallayout"><span class="bold"><b>template</b></span><<span class="bold"><b>typename</b></span> T> <a name="id2375383-bb"></a>variant(T & operand);</pre><p xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><b><span class="term">Requires</span></b>:
- <tt class="computeroutput">T</tt> must be unambiguously convertible to one of
- the bounded types (i.e., <tt class="computeroutput">T1</tt>, <tt class="computeroutput">T2</tt>,
- etc.).<br><b><span class="term">Postconditions</span></b>:
- Content of <tt class="computeroutput">*this</tt> is the best conversion of
- <tt class="computeroutput">operand</tt> to one of the bounded types, as determined
- by standard overload resolution rules.<br><b><span class="term">Throws</span></b>:
- May fail with any exceptions arising from the conversion of
- <tt class="computeroutput">operand</tt> to one of the bounded types.</p></li><li><pre class="literallayout"><span class="bold"><b>template</b></span><<span class="bold"><b>typename</b></span> T> <a name="id2485087-bb"></a>variant(<span class="bold"><b>const</b></span> T & operand);</pre><p xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><b><span class="term">Notes</span></b>:
- Same semantics as previous constructor, but allows
- construction from temporaries.</p></li><li><pre class="literallayout"><span class="bold"><b>template</b></span><<span class="bold"><b>typename</b></span> U1, <span class="bold"><b>typename</b></span> U2, ..., <span class="bold"><b>typename</b></span> UN>
- <a name="id2516325-bb"></a>variant(variant<U1, U2, ..., UN> & operand);</pre><p xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><b><span class="term">Requires</span></b>:
- <span class="emphasis"><em>Every</em></span> one of <tt class="computeroutput">U1</tt>,
- <tt class="computeroutput">U2</tt>, ..., <tt class="computeroutput">UN</tt> must have an unambiguous
- conversion to one of the bounded types (i.e., <tt class="computeroutput">T1</tt>,
- <tt class="computeroutput">T2</tt>, ..., <tt class="computeroutput">TN</tt>).<br><b><span class="term">Postconditions</span></b>:
- If <tt class="computeroutput">variant<U1, U2, ..., UN></tt> is itself
- one of the bounded types, then content of <tt class="computeroutput">*this</tt> is a
- copy of <tt class="computeroutput">operand</tt>. Otherwise, content of
- <tt class="computeroutput">*this</tt> is the best conversion of the content of
- <tt class="computeroutput">operand</tt> to one of the bounded types, as determined
- by standard overload resolution rules.<br><b><span class="term">Throws</span></b>:
- If <tt class="computeroutput">variant<U1, U2, ..., UN></tt> is itself
- one of the bounded types, then may fail with any exceptions arising
- from the copy constructor of
- <tt class="computeroutput">variant<U1, U2, ..., UN></tt>. Otherwise, may fail
- with any exceptions arising from the conversion of the content of
- <tt class="computeroutput">operand</tt> to one of the bounded types.</p></li><li><pre class="literallayout"><span class="bold"><b>template</b></span><<span class="bold"><b>typename</b></span> U1, <span class="bold"><b>typename</b></span> U2, ..., <span class="bold"><b>typename</b></span> UN>
- <a name="id2355967-bb"></a>variant(<span class="bold"><b>const</b></span> variant<U1, U2, ..., UN> & operand);</pre><p xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><b><span class="term">Notes</span></b>:
- Same semantics as previous constructor, but allows
- construction from temporaries.</p></li><li><pre class="literallayout"><a name="id2489745-bb"></a>~variant();</pre><p xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><b><span class="term">Effects</span></b>:
- Destroys the content of <tt class="computeroutput">*this</tt>.<br><b><span class="term">Throws</span></b>:
- Will not throw.</p></li></ol></div></div><div class="refsect2" lang="en"><h3><a name="id2549864-bb"></a><tt class="computeroutput">variant</tt> modifiers</h3><div class="orderedlist"><ol type="1"><li><pre class="literallayout"><span class="type"><span class="bold"><b>void</b></span></span> <a name="id2514140-bb"></a>swap(variant & other);</pre><p xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><b><span class="term">Requires</span></b>:
- Every bounded type must fulfill the requirements of the
- <a href="Assignable.html" title="Concept Assignable">Assignable</a>
- concept.<br><b><span class="term">Effects</span></b>:
- Interchanges the content of <tt class="computeroutput">*this</tt> and
- <tt class="computeroutput">other</tt>.<br><b><span class="term">Throws</span></b>:
- If the contained type of <tt class="computeroutput">other</tt> is the same as
- the contained type of <tt class="computeroutput">*this</tt>, then may fail with any
- exceptions arising from the <tt class="computeroutput">swap</tt> of the contents of
- <tt class="computeroutput">*this</tt> and <tt class="computeroutput">other</tt>. Otherwise, may fail
- with any exceptions arising from either of the copy constructors
- of the contained types. Also, in the event of insufficient
- memory, may fail with <tt class="computeroutput">std::bad_alloc</tt>
- (<a href="variant.design.html#variant.design.never-empty.problem" title="The Implementation Problem">why?</a>).</p></li><li><pre class="literallayout"><span class="type">variant &</span> <a name="id2509331-bb"></a><span class="bold"><b>operator</b></span>=(<span class="bold"><b>const</b></span> variant & rhs);</pre><p xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><b><span class="term">Requires</span></b>:
- Every bounded type must fulfill the requirements of the
- <a href="Assignable.html" title="Concept Assignable">Assignable</a>
- concept.<br><b><span class="term">Effects</span></b>:
- If the contained type of <tt class="computeroutput">rhs</tt> is the same as
- the contained type of <tt class="computeroutput">*this</tt>, then assigns the
- content of <tt class="computeroutput">rhs</tt> into the content of
- <tt class="computeroutput">*this</tt>. Otherwise, makes the content of
- <tt class="computeroutput">*this</tt> a copy of the content of <tt class="computeroutput">rhs</tt>,
- destroying the previous content of <tt class="computeroutput">*this</tt>.<br><b><span class="term">Throws</span></b>:
- If the contained type of <tt class="computeroutput">rhs</tt> is the same as
- the contained type of <tt class="computeroutput">*this</tt>, then may fail with any
- exceptions arising from the assignment of the content of
- <tt class="computeroutput">rhs</tt> into the content <tt class="computeroutput">*this</tt>. Otherwise,
- may fail with any exceptions arising from the copy constructor
- of the contained type of <tt class="computeroutput">rhs</tt>. Also, in the event of
- insufficient memory, may fail with <tt class="computeroutput">std::bad_alloc</tt>
- (<a href="variant.design.html#variant.design.never-empty.problem" title="The Implementation Problem">why?</a>).</p></li><li><pre class="literallayout"><span class="bold"><b>template</b></span><<span class="bold"><b>typename</b></span> T> <span class="type">variant &</span> <a name="id2489594-bb"></a><span class="bold"><b>operator</b></span>=(<span class="bold"><b>const</b></span> T & rhs);</pre><p xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><b><span class="term">Requires</span></b>:
- <div class="itemizedlist"><ul type="disc"><li><tt class="computeroutput">T</tt> must be unambiguously convertible to
- one of the bounded types (i.e., <tt class="computeroutput">T1</tt>,
- <tt class="computeroutput">T2</tt>, etc.).</li><li>Every bounded type must fulfill the requirements of the
- <a href="Assignable.html" title="Concept Assignable">Assignable</a>
- concept.</li></ul></div><br><b><span class="term">Effects</span></b>:
- If the contained type of <tt class="computeroutput">*this</tt> is
- <tt class="computeroutput">T</tt>, then assigns <tt class="computeroutput">rhs</tt> into the content
- of <tt class="computeroutput">*this</tt>. Otherwise, makes the content of
- <tt class="computeroutput">*this</tt> the best conversion of <tt class="computeroutput">rhs</tt> to
- one of the bounded types, as determined by standard overload
- resolution rules, destroying the previous content of
- <tt class="computeroutput">*this</tt>.<br><b><span class="term">Throws</span></b>:
- If the contained type of <tt class="computeroutput">*this</tt> is
- <tt class="computeroutput">T</tt>, then may fail with any exceptions arising from
- the assignment of <tt class="computeroutput">rhs</tt> into the content
- <tt class="computeroutput">*this</tt>. Otherwise, may fail with any exceptions
- arising from the conversion of <tt class="computeroutput">rhs</tt> to one of the
- bounded types. Also, in the event of insufficient memory, may
- fail with <tt class="computeroutput">std::bad_alloc</tt>
- (<a href="variant.design.html#variant.design.never-empty.problem" title="The Implementation Problem">why?</a>).</p></li></ol></div></div><div class="refsect2" lang="en"><h3><a name="id2370110-bb"></a><tt class="computeroutput">variant</tt> queries</h3><div class="orderedlist"><ol type="1"><li><pre class="literallayout"><span class="type"><span class="bold"><b>int</b></span></span> <a name="id2466395-bb"></a>which() <span class="bold"><b>const</b></span>;</pre><p xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><b><span class="term">Returns</span></b>:
- The zero-based index into the set of bounded types
- of the contained type of <tt class="computeroutput">*this</tt>. (For instance, if
- called on a <tt class="computeroutput">variant<int, std::string></tt> object
- containing a <tt class="computeroutput">std::string</tt>, <tt class="computeroutput">which()</tt>
- would return <tt class="computeroutput">1</tt>.)<br><b><span class="term">Throws</span></b>:
- Will not throw.</p></li><li><pre class="literallayout"><span class="type"><span class="bold"><b>bool</b></span></span> <a name="id2494720-bb"></a>empty() <span class="bold"><b>const</b></span>;</pre><p xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><b><span class="term">Returns</span></b>:
- <tt class="computeroutput">false</tt>: <tt class="computeroutput">variant</tt> always contains
- exactly one of its bounded types. (See
- <a href="variant.design.html#variant.design.never-empty" title='"Never-Empty" Guarantee'>the section called “"Never-Empty" Guarantee”</a>
- for more information.)<br><b><span class="term">Rationale</span></b>:
- Facilitates generic compatibility with
- <a href="class.boost.any.html" title="Class any">boost::any</a>.<br><b><span class="term">Throws</span></b>:
- Will not throw.</p></li><li><pre class="literallayout"><span class="type"><span class="bold"><b>const</b></span> std::type_info &</span> <a name="id2508948-bb"></a>type() <span class="bold"><b>const</b></span>;</pre><p xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><b><span class="term">Returns</span></b>:
- <tt class="computeroutput">typeid(x)</tt>, where <tt class="computeroutput">x</tt> is the the
- content of <tt class="computeroutput">*this</tt>.<br><b><span class="term">Throws</span></b>:
- Will not throw.</p></li></ol></div></div><div class="refsect2" lang="en"><h3><a name="id2450166-bb"></a><tt class="computeroutput">variant</tt> relational</h3><div class="orderedlist"><ol type="1"><li><p><a name="id2370129-bb"></a></p><pre class="literallayout"><span class="type"><span class="bold"><b>bool</b></span></span> <a name="id2492818-bb"></a><span class="bold"><b>operator</b></span>==(<span class="bold"><b>const</b></span> variant & rhs) <span class="bold"><b>const</b></span>;
- <span class="bold"><b>template</b></span><<span class="bold"><b>typename</b></span> U> <span class="type"><span class="bold"><b>void</b></span></span> <a name="id2495748-bb"></a><span class="bold"><b>operator</b></span>==(<span class="bold"><b>const</b></span> U & ) <span class="bold"><b>const</b></span>;</pre><p xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><b><span class="term">Notes</span></b>:
- The overload returning <tt class="computeroutput">void</tt> exists only to
- prohibit implicit conversion of the operator's right-hand side
- to <tt class="computeroutput">variant</tt>; thus, its use will (purposefully)
- result in a compile-time error.<br><b><span class="term">Requires</span></b>:
- Every bounded type of the <tt class="computeroutput">variant</tt> must
- fulfill the requirements of the
- <a href="EqualityComparable.html" title="Concept EqualityComparable">EqualityComparable</a>
- concept.<br><b><span class="term">Returns</span></b>:
- <tt class="computeroutput">true</tt> iff <tt class="computeroutput">which() == rhs.which()</tt><span class="emphasis"><em>and</em></span><tt class="computeroutput">content_this == content_rhs</tt>, where
- <tt class="computeroutput">content_this</tt> is the content of <tt class="computeroutput">*this</tt>
- and <tt class="computeroutput">content_rhs</tt> is the content of
- <tt class="computeroutput">rhs</tt>.<br><b><span class="term">Throws</span></b>:
- If <tt class="computeroutput">which() == rhs.which()</tt> then may fail with
- any exceptions arising from <tt class="computeroutput">operator==(T,T)</tt>, where
- <tt class="computeroutput">T</tt> is the contained type of
- <tt class="computeroutput">*this</tt>.</p></li><li><p><a name="id2440328-bb"></a></p><pre class="literallayout"><span class="type"><span class="bold"><b>bool</b></span></span> <a name="id2372301-bb"></a><span class="bold"><b>operator</b></span><(<span class="bold"><b>const</b></span> variant & rhs) <span class="bold"><b>const</b></span>;
- <span class="bold"><b>template</b></span><<span class="bold"><b>typename</b></span> U> <span class="type"><span class="bold"><b>void</b></span></span> <a name="id2433666-bb"></a><span class="bold"><b>operator</b></span><(<span class="bold"><b>const</b></span> U & ) <span class="bold"><b>const</b></span>;</pre><p xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><b><span class="term">Notes</span></b>:
- The overload returning <tt class="computeroutput">void</tt> exists only to
- prohibit implicit conversion of the operator's right-hand side
- to <tt class="computeroutput">variant</tt>; thus, its use will (purposefully)
- result in a compile-time error.<br><b><span class="term">Requires</span></b>:
- Every bounded type of the <tt class="computeroutput">variant</tt> must
- fulfill the requirements of the
- <a href="LessThanComparable.html" title="Concept LessThanComparable">LessThanComparable</a>
- concept.<br><b><span class="term">Returns</span></b>:
- If <tt class="computeroutput">which() == rhs.which()</tt> then:
- <tt class="computeroutput">content_this < content_rhs</tt>, where
- <tt class="computeroutput">content_this</tt> is the content of <tt class="computeroutput">*this</tt>
- and <tt class="computeroutput">content_rhs</tt> is the content of <tt class="computeroutput">rhs</tt>.
- Otherwise: <tt class="computeroutput">which() < rhs.which()</tt>.<br><b><span class="term">Throws</span></b>:
- If <tt class="computeroutput">which() == rhs.which()</tt> then may fail with
- any exceptions arising from <tt class="computeroutput">operator<(T,T)</tt>,
- where <tt class="computeroutput">T</tt> is the contained type of
- <tt class="computeroutput">*this</tt>.</p></li></ol></div></div></div></div><table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr><td align="left"><small>Last revised: , at GMT</small></td><td align="right"><small>Copyright © 2002, 2003 Eric Friedman, Itay Maman</small></td></tr></table><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="BOOST_VARIANT_NO_FULL_RECURSIVE_VARIANT_SUPPORT.html"><img src="images/prev.png" alt="Prev"></a> </td><td width="20%" align="center"><a accesskey="u" href="variant.reference.html#header.boost.variant.variant.hpp"><img src="images/up.png" alt="Up"></a></td><td width="40%" align="right"> <a accesskey="n" href="id2518553-bb.html"><img src="images/next.png" alt="Next"></a></td></tr><tr><td width="40%" align="left" valign="top">Macro BOOST_VARIANT_NO_FULL_RECURSIVE_VARIANT_SUPPORT </td><td width="20%" align="center"><a accesskey="h" href="index.html"><img src="images/home.png" alt="Home"></a></td><td width="40%" align="right" valign="top"> Function template swap</td></tr></table></div></body></html>
|