Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/doc/html/boost/variant.html @ 12

Last change on this file since 12 was 12, checked in by landauf, 18 years ago

added boost

File size: 31.7 KB
Line 
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
4<title>Class template variant</title>
5<link rel="stylesheet" href="../boostbook.css" type="text/css">
6<meta name="generator" content="DocBook XSL Stylesheets V1.69.1">
7<link rel="start" href="../index.html" title="The Boost C++ Libraries">
8<link rel="up" href="../variant/reference.html#id2540137" title="Header &lt;boost/variant/variant.hpp&gt;">
9<link rel="prev" href="../id2404411.html" title="Macro BOOST_VARIANT_NO_FULL_RECURSIVE_VARIANT_SUPPORT">
10<link rel="next" href="../id2629621.html" title="Function template swap">
11</head>
12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
13<table cellpadding="2" width="100%">
14<td valign="top"><img alt="boost.png (6897 bytes)" width="277" height="86" src="../../../boost.png"></td>
15<td align="center"><a href="../../../index.htm">Home</a></td>
16<td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td>
17<td align="center"><a href="../../../people/people.htm">People</a></td>
18<td align="center"><a href="../../../more/faq.htm">FAQ</a></td>
19<td align="center"><a href="../../../more/index.htm">More</a></td>
20</table>
21<hr>
22<div class="spirit-nav">
23<a accesskey="p" href="../id2404411.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../variant/reference.html#id2540137"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="../id2629621.html"><img src="../images/next.png" alt="Next"></a>
24</div>
25<div class="refentry" lang="en">
26<a name="boost.variant"></a><div class="titlepage"></div>
27<div class="refnamediv">
28<h2><span class="refentrytitle">Class template variant</span></h2>
29<p>boost::variant &#8212; Safe, generic, stack-based discriminated union container.</p>
30</div>
31<h2 xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv-title">Synopsis</h2>
32<div xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv"><pre class="synopsis"><span class="bold"><strong>template</strong></span>&lt;<span class="bold"><strong>typename</strong></span> T1, <span class="bold"><strong>typename</strong></span> T2 = <span class="emphasis"><em>unspecified</em></span>, ...,
33         <span class="bold"><strong>typename</strong></span> TN = <span class="emphasis"><em>unspecified</em></span>&gt; 
34<span class="bold"><strong>class</strong></span> variant {
35<span class="bold"><strong>public</strong></span>:
36  <span class="emphasis"><em>// types</em></span>
37  <span class="bold"><strong>typedef</strong></span> <span class="emphasis"><em>unspecified</em></span> types;
38
39  <span class="emphasis"><em>// <a href="variant.html#boost.variantconstruct-copy-destruct">construct/copy/destruct</a></em></span>
40  <a href="variant.html#id2669768-bb">variant</a>();
41  <a href="variant.html#id2558506-bb">variant</a>(<span class="bold"><strong>const</strong></span> variant &amp;);
42  <span class="bold"><strong>template</strong></span>&lt;<span class="bold"><strong>typename</strong></span> T&gt; <a href="variant.html#id2655492-bb">variant</a>(T &amp;);
43  <span class="bold"><strong>template</strong></span>&lt;<span class="bold"><strong>typename</strong></span> T&gt; <a href="variant.html#id2667505-bb">variant</a>(<span class="bold"><strong>const</strong></span> T &amp;);
44  <span class="bold"><strong>template</strong></span>&lt;<span class="bold"><strong>typename</strong></span> U1, <span class="bold"><strong>typename</strong></span> U2, ..., <span class="bold"><strong>typename</strong></span> UN&gt; 
45    <a href="variant.html#id2651596-bb">variant</a>(variant&lt;U1, U2, ..., UN&gt; &amp;);
46  <span class="bold"><strong>template</strong></span>&lt;<span class="bold"><strong>typename</strong></span> U1, <span class="bold"><strong>typename</strong></span> U2, ..., <span class="bold"><strong>typename</strong></span> UN&gt; 
47    <a href="variant.html#id2343764-bb">variant</a>(<span class="bold"><strong>const</strong></span> variant&lt;U1, U2, ..., UN&gt; &amp;);
48  <a href="variant.html#id2643506-bb">~variant</a>();
49
50  <span class="emphasis"><em>// <a href="variant.html#id2649848-bb">modifiers</a></em></span>
51  <span class="type"><span class="bold"><strong>void</strong></span></span> <a href="variant.html#id2641473-bb">swap</a>(variant &amp;);
52  <span class="type">variant &amp;</span> <a href="variant.html#id2394797-bb"><span class="bold"><strong>operator</strong></span>=</a>(<span class="bold"><strong>const</strong></span> variant &amp;);
53  <span class="bold"><strong>template</strong></span>&lt;<span class="bold"><strong>typename</strong></span> T&gt; <span class="type">variant &amp;</span> <a href="variant.html#id2630357-bb"><span class="bold"><strong>operator</strong></span>=</a>(<span class="bold"><strong>const</strong></span> T &amp;);
54
55  <span class="emphasis"><em>// <a href="variant.html#id2632746-bb">queries</a></em></span>
56  <span class="type"><span class="bold"><strong>int</strong></span></span> <a href="variant.html#id2632967-bb">which</a>() <span class="bold"><strong>const</strong></span>;
57  <span class="type"><span class="bold"><strong>bool</strong></span></span> <a href="variant.html#id2632549-bb">empty</a>() <span class="bold"><strong>const</strong></span>;
58  <span class="type"><span class="bold"><strong>const</strong></span> std::type_info &amp;</span> <a href="variant.html#id2632986-bb">type</a>() <span class="bold"><strong>const</strong></span>;
59
60  <span class="emphasis"><em>// <a href="variant.html#id2630380-bb">relational</a></em></span>
61  <span class="type"><span class="bold"><strong>bool</strong></span></span> <a href="variant.html#id2607215-bb"><span class="bold"><strong>operator</strong></span>==</a>(<span class="bold"><strong>const</strong></span> variant &amp;) <span class="bold"><strong>const</strong></span>;
62  <span class="bold"><strong>template</strong></span>&lt;<span class="bold"><strong>typename</strong></span> U&gt; <span class="type"><span class="bold"><strong>void</strong></span></span> <a href="variant.html#id2633638-bb"><span class="bold"><strong>operator</strong></span>==</a>(<span class="bold"><strong>const</strong></span> U &amp;) <span class="bold"><strong>const</strong></span>;
63  <span class="type"><span class="bold"><strong>bool</strong></span></span> <a href="variant.html#id2653100-bb"><span class="bold"><strong>operator</strong></span>&lt;</a>(<span class="bold"><strong>const</strong></span> variant &amp;) <span class="bold"><strong>const</strong></span>;
64  <span class="bold"><strong>template</strong></span>&lt;<span class="bold"><strong>typename</strong></span> U&gt; <span class="type"><span class="bold"><strong>void</strong></span></span> <a href="variant.html#id2667559-bb"><span class="bold"><strong>operator</strong></span>&lt;</a>(<span class="bold"><strong>const</strong></span> U &amp;) <span class="bold"><strong>const</strong></span>;
65};</pre></div>
66<div class="refsect1" lang="en">
67<a name="id2833563"></a><h2>Description</h2>
68<p>The <code class="computeroutput">variant</code> class template (inspired by Andrei
69        Alexandrescu's class of the same name
70        [<a href="../variant/refs.html#variant.refs.ale01a">Ale01A</a>]) is an efficient,
71        <a href="../variant/tutorial.html#variant.tutorial.recursive" title="Recursive variant types">recursive-capable</a>,
72        bounded discriminated union value type capable of containing any value
73        type (either POD or non-POD). It supports construction from any type
74        convertible to one of its bounded types or from a source
75        <code class="computeroutput">variant</code> whose bounded types are each convertible to one
76        of the destination <code class="computeroutput">variant</code>'s bounded types. As well,
77        through <code class="computeroutput"><a href="../apply_visitor.html" title="Function apply_visitor">apply_visitor</a></code>,
78        <code class="computeroutput">variant</code> supports compile-time checked, type-safe
79        visitation; and through <code class="computeroutput"><a href="../get.html" title="Function get">get</a></code>,
80        <code class="computeroutput">variant</code> supports run-time checked, type-safe value
81        retrieval.</p>
82<p><span class="bold"><strong>Notes</strong></span>:</p>
83<div class="itemizedlist"><ul type="disc">
84<li>The bounded types of the <code class="computeroutput">variant</code> are exposed
85            via the nested typedef <code class="computeroutput">types</code>, which is an
86            <a href="../../../libs/mpl/index.html" target="_top">MPL</a>-compatible Sequence containing the
87            set of types that must be handled by any
88            <a href="../variant/reference.html#variant.concepts.static-visitor" title="StaticVisitor">visitor</a> to
89            the <code class="computeroutput">variant</code>.</li>
90<li>All members of <code class="computeroutput">variant</code> satisfy at least the
91            basic guarantee of exception-safety. That is, all operations on
92            a <code class="computeroutput">variant</code> remain defined even after previous
93            operations have failed.</li>
94<li>Each type specified as a template argument to
95            <code class="computeroutput">variant</code> must meet the requirements of the
96            <span class="emphasis"><em><a href="../variant/reference.html#variant.concepts.bounded-type" title="BoundedType">BoundedType</a></em></span>
97            concept.</li>
98<li>Each type specified as a template argument to
99            <code class="computeroutput">variant</code> must be distinct after removal of qualifiers.
100            Thus, for instance, both <code class="computeroutput">variant&lt;int, int&gt;</code> and
101            <code class="computeroutput">variant&lt;int, const int&gt;</code> have undefined
102            behavior.</li>
103<li>Conforming implementations of <code class="computeroutput">variant</code> must
104            allow at least ten types as template arguments. The exact number
105            of allowed arguments is exposed by the preprocessor macro
106            <code class="computeroutput"><a href="../BOOST_VARIANT_LIMIT_TYPES.html" title="Macro BOOST_VARIANT_LIMIT_TYPES">BOOST_VARIANT_LIMIT_TYPES</a></code>.
107            (See <code class="computeroutput"><a href="../make_variant_over.html" title="Class template make_variant_over">make_variant_over</a></code> for a
108            means to specify the bounded types of a <code class="computeroutput">variant</code> by
109            the elements of an <a href="../../../libs/mpl/index.html" target="_top">MPL</a> or compatible
110            Sequence, thus overcoming this limitation.)</li>
111</ul></div>
112<div class="refsect2" lang="en">
113<a name="id2833797"></a><h3>
114<a name="boost.variantconstruct-copy-destruct"></a><code class="computeroutput">variant</code> construct/copy/destruct</h3>
115<div class="orderedlist"><ol type="1">
116<li>
117<pre class="literallayout"><a name="id2669768-bb"></a>variant();</pre>
118<p><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Requires</span></b>:
119
120    The first bounded type of the <code class="computeroutput">variant</code> (i.e.,
121            <code class="computeroutput">T1</code>) must fulfill the requirements of the
122            <span class="emphasis"><em>DefaultConstructible</em></span> [20.1.4]
123            concept.<br><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Postconditions</span></b>:
124
125    Content of <code class="computeroutput">*this</code> is the default value of the
126            first bounded type (i.e, <code class="computeroutput">T1</code>).<br><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Throws</span></b>:
127
128    May fail with any exceptions arising from the default
129            constructor of <code class="computeroutput">T1</code>.</p>
130</li>
131<li>
132<pre class="literallayout"><a name="id2558506-bb"></a>variant(<span class="bold"><strong>const</strong></span> variant &amp; other);</pre>
133<p><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Postconditions</span></b>:
134
135    Content of <code class="computeroutput">*this</code> is a copy of the content of
136            <code class="computeroutput">other</code>.<br><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Throws</span></b>:
137
138    May fail with any exceptions arising from the
139            copy constructor of <code class="computeroutput">other</code>'s contained type.</p>
140</li>
141<li>
142<pre class="literallayout"><span class="bold"><strong>template</strong></span>&lt;<span class="bold"><strong>typename</strong></span> T&gt; <a name="id2655492-bb"></a>variant(T &amp; operand);</pre>
143<p><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Requires</span></b>:
144
145    <code class="computeroutput">T</code> must be unambiguously convertible to one of
146            the bounded types (i.e., <code class="computeroutput">T1</code>, <code class="computeroutput">T2</code>,
147            etc.).<br><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Postconditions</span></b>:
148
149    Content of <code class="computeroutput">*this</code> is the best conversion of
150            <code class="computeroutput">operand</code> to one of the bounded types, as determined
151            by standard overload resolution rules.<br><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Throws</span></b>:
152
153    May fail with any exceptions arising from the conversion of
154            <code class="computeroutput">operand</code> to one of the bounded types.</p>
155</li>
156<li>
157<pre class="literallayout"><span class="bold"><strong>template</strong></span>&lt;<span class="bold"><strong>typename</strong></span> T&gt; <a name="id2667505-bb"></a>variant(<span class="bold"><strong>const</strong></span> T &amp; operand);</pre>
158<p><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Notes</span></b>:
159
160    Same semantics as previous constructor, but allows
161            construction from temporaries.</p>
162</li>
163<li>
164<pre class="literallayout"><span class="bold"><strong>template</strong></span>&lt;<span class="bold"><strong>typename</strong></span> U1, <span class="bold"><strong>typename</strong></span> U2, ..., <span class="bold"><strong>typename</strong></span> UN&gt; 
165  <a name="id2651596-bb"></a>variant(variant&lt;U1, U2, ..., UN&gt; &amp; operand);</pre>
166<p><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Requires</span></b>:
167
168    <span class="emphasis"><em>Every</em></span> one of <code class="computeroutput">U1</code>,
169            <code class="computeroutput">U2</code>, ..., <code class="computeroutput">UN</code> must have an unambiguous
170            conversion to one of the bounded types (i.e., <code class="computeroutput">T1</code>,
171            <code class="computeroutput">T2</code>, ..., <code class="computeroutput">TN</code>).<br><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Postconditions</span></b>:
172
173    If <code class="computeroutput">variant&lt;U1, U2, ..., UN&gt;</code> is itself
174            one of the bounded types, then content of <code class="computeroutput">*this</code> is a
175            copy of <code class="computeroutput">operand</code>. Otherwise, content of
176            <code class="computeroutput">*this</code> is the best conversion of the content of
177            <code class="computeroutput">operand</code> to one of the bounded types, as determined
178            by standard overload resolution rules.<br><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Throws</span></b>:
179
180    If <code class="computeroutput">variant&lt;U1, U2, ..., UN&gt;</code> is itself
181          one of the bounded types, then may fail with any exceptions arising
182          from the copy constructor of
183          <code class="computeroutput">variant&lt;U1, U2, ..., UN&gt;</code>. Otherwise, may fail
184          with any exceptions arising from the conversion of the content of
185          <code class="computeroutput">operand</code> to one of the bounded types.</p>
186</li>
187<li>
188<pre class="literallayout"><span class="bold"><strong>template</strong></span>&lt;<span class="bold"><strong>typename</strong></span> U1, <span class="bold"><strong>typename</strong></span> U2, ..., <span class="bold"><strong>typename</strong></span> UN&gt; 
189  <a name="id2343764-bb"></a>variant(<span class="bold"><strong>const</strong></span> variant&lt;U1, U2, ..., UN&gt; &amp; operand);</pre>
190<p><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Notes</span></b>:
191
192    Same semantics as previous constructor, but allows
193            construction from temporaries.</p>
194</li>
195<li>
196<pre class="literallayout"><a name="id2643506-bb"></a>~variant();</pre>
197<p><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Effects</span></b>:
198
199    Destroys the content of <code class="computeroutput">*this</code>.<br><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Throws</span></b>:
200
201    Will not throw.</p>
202</li>
203</ol></div>
204</div>
205<div class="refsect2" lang="en">
206<a name="id2834336"></a><h3>
207<a name="id2649848-bb"></a><code class="computeroutput">variant</code> modifiers</h3>
208<div class="orderedlist"><ol type="1">
209<li>
210<pre class="literallayout"><span class="type"><span class="bold"><strong>void</strong></span></span> <a name="id2641473-bb"></a>swap(variant &amp; other);</pre>
211<p><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Requires</span></b>:
212
213    Every bounded type must fulfill the requirements of the
214              <a href="../Assignable.html" title="Concept Assignable">Assignable</a>
215              concept.<br><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Effects</span></b>:
216
217    Interchanges the content of <code class="computeroutput">*this</code> and
218              <code class="computeroutput">other</code>.<br><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Throws</span></b>:
219
220    If the contained type of <code class="computeroutput">other</code> is the same as
221              the contained type of <code class="computeroutput">*this</code>, then may fail with any
222              exceptions arising from the <code class="computeroutput">swap</code> of the contents of
223              <code class="computeroutput">*this</code> and <code class="computeroutput">other</code>. Otherwise, may fail
224              with any exceptions arising from either of the copy constructors
225              of the contained types. Also, in the event of insufficient
226              memory, may fail with <code class="computeroutput">std::bad_alloc</code>
227              (<a href="../variant/design.html#variant.design.never-empty.problem" title="The Implementation Problem">why?</a>).</p>
228</li>
229<li>
230<pre class="literallayout"><span class="type">variant &amp;</span> <a name="id2394797-bb"></a><span class="bold"><strong>operator</strong></span>=(<span class="bold"><strong>const</strong></span> variant &amp; rhs);</pre>
231<p><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Requires</span></b>:
232
233    Every bounded type must fulfill the requirements of the
234              <a href="../Assignable.html" title="Concept Assignable">Assignable</a>
235              concept.<br><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Effects</span></b>:
236
237    If the contained type of <code class="computeroutput">rhs</code> is the same as
238              the contained type of <code class="computeroutput">*this</code>, then assigns the
239              content of <code class="computeroutput">rhs</code> into the content of
240              <code class="computeroutput">*this</code>. Otherwise, makes the content of
241              <code class="computeroutput">*this</code> a copy of the content of <code class="computeroutput">rhs</code>,
242              destroying the previous content of <code class="computeroutput">*this</code>.<br><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Throws</span></b>:
243
244    If the contained type of <code class="computeroutput">rhs</code> is the same as
245              the contained type of <code class="computeroutput">*this</code>, then may fail with any
246              exceptions arising from the assignment of the content of
247              <code class="computeroutput">rhs</code> into the content <code class="computeroutput">*this</code>. Otherwise,
248              may fail with any exceptions arising from the copy constructor
249              of the contained type of <code class="computeroutput">rhs</code>. Also, in the event of
250              insufficient memory, may fail with <code class="computeroutput">std::bad_alloc</code>
251              (<a href="../variant/design.html#variant.design.never-empty.problem" title="The Implementation Problem">why?</a>).</p>
252</li>
253<li>
254<pre class="literallayout"><span class="bold"><strong>template</strong></span>&lt;<span class="bold"><strong>typename</strong></span> T&gt; <span class="type">variant &amp;</span> <a name="id2630357-bb"></a><span class="bold"><strong>operator</strong></span>=(<span class="bold"><strong>const</strong></span> T &amp; rhs);</pre>
255<p><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Requires</span></b>:
256
257    <div class="itemizedlist"><ul type="disc">
258<li>
259<code class="computeroutput">T</code> must be unambiguously convertible to
260                one of the bounded types (i.e., <code class="computeroutput">T1</code>,
261                <code class="computeroutput">T2</code>, etc.).</li>
262<li>Every bounded type must fulfill the requirements of the
263                <a href="../Assignable.html" title="Concept Assignable">Assignable</a>
264                concept.</li>
265</ul></div><br><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Effects</span></b>:
266
267    If the contained type of <code class="computeroutput">*this</code> is
268              <code class="computeroutput">T</code>, then assigns <code class="computeroutput">rhs</code> into the content
269              of <code class="computeroutput">*this</code>. Otherwise, makes the content of
270              <code class="computeroutput">*this</code> the best conversion of <code class="computeroutput">rhs</code> to
271              one of the bounded types, as determined by standard overload
272              resolution rules, destroying the previous content of
273              <code class="computeroutput">*this</code>.<br><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Throws</span></b>:
274
275    If the contained type of <code class="computeroutput">*this</code> is
276              <code class="computeroutput">T</code>, then may fail with any exceptions arising from
277              the assignment of <code class="computeroutput">rhs</code> into the content
278              <code class="computeroutput">*this</code>. Otherwise, may fail with any exceptions
279              arising from the conversion of <code class="computeroutput">rhs</code> to one of the
280              bounded types. Also, in the event of insufficient memory, may
281              fail with <code class="computeroutput">std::bad_alloc</code>
282              (<a href="../variant/design.html#variant.design.never-empty.problem" title="The Implementation Problem">why?</a>).</p>
283</li>
284</ol></div>
285</div>
286<div class="refsect2" lang="en">
287<a name="id2834814"></a><h3>
288<a name="id2632746-bb"></a><code class="computeroutput">variant</code> queries</h3>
289<div class="orderedlist"><ol type="1">
290<li>
291<pre class="literallayout"><span class="type"><span class="bold"><strong>int</strong></span></span> <a name="id2632967-bb"></a>which() <span class="bold"><strong>const</strong></span>;</pre>
292<p><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Returns</span></b>:
293
294    The zero-based index into the set of bounded types
295              of the contained type of <code class="computeroutput">*this</code>. (For instance, if
296              called on a <code class="computeroutput">variant&lt;int, std::string&gt;</code> object
297              containing a <code class="computeroutput">std::string</code>, <code class="computeroutput">which()</code>
298              would return <code class="computeroutput">1</code>.)<br><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Throws</span></b>:
299
300    Will not throw.</p>
301</li>
302<li>
303<pre class="literallayout"><span class="type"><span class="bold"><strong>bool</strong></span></span> <a name="id2632549-bb"></a>empty() <span class="bold"><strong>const</strong></span>;</pre>
304<p><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Returns</span></b>:
305
306    <code class="computeroutput">false</code>: <code class="computeroutput">variant</code> always contains
307              exactly one of its bounded types. (See
308              <a href="../variant/design.html#variant.design.never-empty" title='"Never-Empty" Guarantee'>the section called &#8220;"Never-Empty" Guarantee&#8221;</a>
309              for more information.)<br><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Rationale</span></b>:
310
311    Facilitates generic compatibility with
312              <a href="any.html" title="Class any">boost::any</a>.<br><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Throws</span></b>:
313
314    Will not throw.</p>
315</li>
316<li>
317<pre class="literallayout"><span class="type"><span class="bold"><strong>const</strong></span> std::type_info &amp;</span> <a name="id2632986-bb"></a>type() <span class="bold"><strong>const</strong></span>;</pre>
318<p><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Returns</span></b>:
319
320    <code class="computeroutput">typeid(x)</code>, where <code class="computeroutput">x</code> is the the
321              content of <code class="computeroutput">*this</code>.<br><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Throws</span></b>:
322
323    Will not throw.</p>
324</li>
325</ol></div>
326</div>
327<div class="refsect2" lang="en">
328<a name="id2835044"></a><h3>
329<a name="id2630380-bb"></a><code class="computeroutput">variant</code> relational</h3>
330<div class="orderedlist"><ol type="1">
331<li>
332<p><a name="id2535038-bb"></a></p>
333<pre class="literallayout"><span class="type"><span class="bold"><strong>bool</strong></span></span> <a name="id2607215-bb"></a><span class="bold"><strong>operator</strong></span>==(<span class="bold"><strong>const</strong></span> variant &amp; rhs) <span class="bold"><strong>const</strong></span>;
334<span class="bold"><strong>template</strong></span>&lt;<span class="bold"><strong>typename</strong></span> U&gt; <span class="type"><span class="bold"><strong>void</strong></span></span> <a name="id2633638-bb"></a><span class="bold"><strong>operator</strong></span>==(<span class="bold"><strong>const</strong></span> U &amp; ) <span class="bold"><strong>const</strong></span>;</pre>
335<p><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Notes</span></b>:
336
337    The overload returning <code class="computeroutput">void</code> exists only to
338              prohibit implicit conversion of the operator's right-hand side
339              to <code class="computeroutput">variant</code>; thus, its use will (purposefully)
340              result in a compile-time error.<br><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Requires</span></b>:
341
342    Every bounded type of the <code class="computeroutput">variant</code> must
343              fulfill the requirements of the
344              <a href="../EqualityComparable.html" title="Concept EqualityComparable">EqualityComparable</a>
345              concept.<br><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Returns</span></b>:
346
347    <code class="computeroutput">true</code> iff <code class="computeroutput">which() == rhs.which()</code><span class="emphasis"><em>and</em></span><code class="computeroutput">content_this == content_rhs</code>, where
348              <code class="computeroutput">content_this</code> is the content of <code class="computeroutput">*this</code>
349              and <code class="computeroutput">content_rhs</code> is the content of
350              <code class="computeroutput">rhs</code>.<br><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Throws</span></b>:
351
352    If <code class="computeroutput">which() == rhs.which()</code> then may fail with
353              any exceptions arising from <code class="computeroutput">operator==(T,T)</code>, where
354              <code class="computeroutput">T</code> is the contained type of
355              <code class="computeroutput">*this</code>.</p>
356</li>
357<li>
358<p><a name="id2576152-bb"></a></p>
359<pre class="literallayout"><span class="type"><span class="bold"><strong>bool</strong></span></span> <a name="id2653100-bb"></a><span class="bold"><strong>operator</strong></span>&lt;(<span class="bold"><strong>const</strong></span> variant &amp; rhs) <span class="bold"><strong>const</strong></span>;
360<span class="bold"><strong>template</strong></span>&lt;<span class="bold"><strong>typename</strong></span> U&gt; <span class="type"><span class="bold"><strong>void</strong></span></span> <a name="id2667559-bb"></a><span class="bold"><strong>operator</strong></span>&lt;(<span class="bold"><strong>const</strong></span> U &amp; ) <span class="bold"><strong>const</strong></span>;</pre>
361<p><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Notes</span></b>:
362
363    The overload returning <code class="computeroutput">void</code> exists only to
364              prohibit implicit conversion of the operator's right-hand side
365              to <code class="computeroutput">variant</code>; thus, its use will (purposefully)
366              result in a compile-time error.<br><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Requires</span></b>:
367
368    Every bounded type of the <code class="computeroutput">variant</code> must
369              fulfill the requirements of the
370              <a href="../LessThanComparable.html" title="Concept LessThanComparable">LessThanComparable</a>
371              concept.<br><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Returns</span></b>:
372
373    If <code class="computeroutput">which() == rhs.which()</code> then:
374              <code class="computeroutput">content_this &lt; content_rhs</code>, where
375              <code class="computeroutput">content_this</code> is the content of <code class="computeroutput">*this</code>
376              and <code class="computeroutput">content_rhs</code> is the content of <code class="computeroutput">rhs</code>.
377              Otherwise: <code class="computeroutput">which() &lt; rhs.which()</code>.<br><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Throws</span></b>:
378
379    If <code class="computeroutput">which() == rhs.which()</code> then may fail with
380              any exceptions arising from <code class="computeroutput">operator&lt;(T,T)</code>,
381              where <code class="computeroutput">T</code> is the contained type of
382              <code class="computeroutput">*this</code>.</p>
383</li>
384</ol></div>
385</div>
386</div>
387</div>
388<table width="100%"><tr>
389<td align="left"></td>
390<td align="right"><small>Copyright © 2002, 2003 Eric Friedman, Itay Maman</small></td>
391</tr></table>
392<hr>
393<div class="spirit-nav">
394<a accesskey="p" href="../id2404411.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../variant/reference.html#id2540137"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="../id2629621.html"><img src="../images/next.png" alt="Next"></a>
395</div>
396</body>
397</html>
Note: See TracBrowser for help on using the repository browser.