| 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.68.1"> |
|---|
| 7 | <link rel="start" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset"> |
|---|
| 8 | <link rel="up" href="../variant/reference.html#header.boost.variant.variant.hpp" title="Header <boost/variant/variant.hpp>"> |
|---|
| 9 | <link rel="prev" href="../BOOST_VARIANT_NO_FULL_RECURSIVE_VARIANT_SUPPORT.html" title="Macro BOOST_VARIANT_NO_FULL_RECURSIVE_VARIANT_SUPPORT"> |
|---|
| 10 | <link rel="next" href="../id1599586-bb.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 C++ Libraries" 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="../BOOST_VARIANT_NO_FULL_RECURSIVE_VARIANT_SUPPORT.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../variant/reference.html#header.boost.variant.variant.hpp"><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="../id1599586-bb.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 — 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><<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>> |
|---|
| 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#id1602028-bb">variant</a>(); |
|---|
| 41 | <a href="variant.html#id1599613-bb">variant</a>(<span class="bold"><strong>const</strong></span> variant &); |
|---|
| 42 | <span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> T> <a href="variant.html#id1254269-bb">variant</a>(T &); |
|---|
| 43 | <span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> T> <a href="variant.html#id1636459-bb">variant</a>(<span class="bold"><strong>const</strong></span> T &); |
|---|
| 44 | <span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> U1, <span class="bold"><strong>typename</strong></span> U2, ..., <span class="bold"><strong>typename</strong></span> UN> |
|---|
| 45 | <a href="variant.html#id1604404-bb">variant</a>(variant<U1, U2, ..., UN> &); |
|---|
| 46 | <span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> U1, <span class="bold"><strong>typename</strong></span> U2, ..., <span class="bold"><strong>typename</strong></span> UN> |
|---|
| 47 | <a href="variant.html#id1630438-bb">variant</a>(<span class="bold"><strong>const</strong></span> variant<U1, U2, ..., UN> &); |
|---|
| 48 | <a href="variant.html#id1601741-bb">~variant</a>(); |
|---|
| 49 | |
|---|
| 50 | <span class="emphasis"><em>// <a href="variant.html#id790460-bb">modifiers</a></em></span> |
|---|
| 51 | <span class="type"><span class="bold"><strong>void</strong></span></span> <a href="variant.html#id790464-bb">swap</a>(variant &); |
|---|
| 52 | <span class="type">variant &</span> <a href="variant.html#id1669309-bb"><span class="bold"><strong>operator</strong></span>=</a>(<span class="bold"><strong>const</strong></span> variant &); |
|---|
| 53 | <span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> T> <span class="type">variant &</span> <a href="variant.html#id1634032-bb"><span class="bold"><strong>operator</strong></span>=</a>(<span class="bold"><strong>const</strong></span> T &); |
|---|
| 54 | |
|---|
| 55 | <span class="emphasis"><em>// <a href="variant.html#id1572706-bb">queries</a></em></span> |
|---|
| 56 | <span class="type"><span class="bold"><strong>int</strong></span></span> <a href="variant.html#id1572710-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#id1631554-bb">empty</a>() <span class="bold"><strong>const</strong></span>; |
|---|
| 58 | <span class="type"><span class="bold"><strong>const</strong></span> std::type_info &</span> <a href="variant.html#id1005344-bb">type</a>() <span class="bold"><strong>const</strong></span>; |
|---|
| 59 | |
|---|
| 60 | <span class="emphasis"><em>// <a href="variant.html#id1636712-bb">relational</a></em></span> |
|---|
| 61 | <span class="type"><span class="bold"><strong>bool</strong></span></span> <a href="variant.html#id1011694-bb"><span class="bold"><strong>operator</strong></span>==</a>(<span class="bold"><strong>const</strong></span> variant &) <span class="bold"><strong>const</strong></span>; |
|---|
| 62 | <span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> U> <span class="type"><span class="bold"><strong>void</strong></span></span> <a href="variant.html#id1673222-bb"><span class="bold"><strong>operator</strong></span>==</a>(<span class="bold"><strong>const</strong></span> U &) <span class="bold"><strong>const</strong></span>; |
|---|
| 63 | <span class="type"><span class="bold"><strong>bool</strong></span></span> <a href="variant.html#id1638199-bb"><span class="bold"><strong>operator</strong></span><</a>(<span class="bold"><strong>const</strong></span> variant &) <span class="bold"><strong>const</strong></span>; |
|---|
| 64 | <span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> U> <span class="type"><span class="bold"><strong>void</strong></span></span> <a href="variant.html#id1638215-bb"><span class="bold"><strong>operator</strong></span><</a>(<span class="bold"><strong>const</strong></span> U &) <span class="bold"><strong>const</strong></span>; |
|---|
| 65 | };</pre></div> |
|---|
| 66 | <div class="refsect1" lang="en"> |
|---|
| 67 | <a name="id1944701"></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<int, int></code> and |
|---|
| 101 | <code class="computeroutput">variant<int, const int></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="id1944944"></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="id1602028-bb"></a>variant();</pre> |
|---|
| 118 | <div class="variablelist"><table border="0"> |
|---|
| 119 | <col align="left" valign="top"> |
|---|
| 120 | <tbody> |
|---|
| 121 | <tr> |
|---|
| 122 | <td> |
|---|
| 123 | <span class="term">Requires:</span></td> |
|---|
| 124 | <td>The first bounded type of the <code class="computeroutput">variant</code> (i.e., |
|---|
| 125 | <code class="computeroutput">T1</code>) must fulfill the requirements of the |
|---|
| 126 | <span class="emphasis"><em>DefaultConstructible</em></span> [20.1.4] |
|---|
| 127 | concept.</td> |
|---|
| 128 | </tr> |
|---|
| 129 | <tr> |
|---|
| 130 | <td> |
|---|
| 131 | <span class="term">Postconditions:</span></td> |
|---|
| 132 | <td>Content of <code class="computeroutput">*this</code> is the default value of the |
|---|
| 133 | first bounded type (i.e, <code class="computeroutput">T1</code>).</td> |
|---|
| 134 | </tr> |
|---|
| 135 | <tr> |
|---|
| 136 | <td> |
|---|
| 137 | <span class="term">Throws:</span></td> |
|---|
| 138 | <td>May fail with any exceptions arising from the default |
|---|
| 139 | constructor of <code class="computeroutput">T1</code>.</td> |
|---|
| 140 | </tr> |
|---|
| 141 | </tbody> |
|---|
| 142 | </table></div> |
|---|
| 143 | </li> |
|---|
| 144 | <li> |
|---|
| 145 | <pre class="literallayout"><a name="id1599613-bb"></a>variant(<span class="bold"><strong>const</strong></span> variant & other);</pre> |
|---|
| 146 | <div class="variablelist"><table border="0"> |
|---|
| 147 | <col align="left" valign="top"> |
|---|
| 148 | <tbody> |
|---|
| 149 | <tr> |
|---|
| 150 | <td> |
|---|
| 151 | <span class="term">Postconditions:</span></td> |
|---|
| 152 | <td>Content of <code class="computeroutput">*this</code> is a copy of the content of |
|---|
| 153 | <code class="computeroutput">other</code>.</td> |
|---|
| 154 | </tr> |
|---|
| 155 | <tr> |
|---|
| 156 | <td> |
|---|
| 157 | <span class="term">Throws:</span></td> |
|---|
| 158 | <td>May fail with any exceptions arising from the |
|---|
| 159 | copy constructor of <code class="computeroutput">other</code>'s contained type.</td> |
|---|
| 160 | </tr> |
|---|
| 161 | </tbody> |
|---|
| 162 | </table></div> |
|---|
| 163 | </li> |
|---|
| 164 | <li> |
|---|
| 165 | <pre class="literallayout"><span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> T> <a name="id1254269-bb"></a>variant(T & operand);</pre> |
|---|
| 166 | <div class="variablelist"><table border="0"> |
|---|
| 167 | <col align="left" valign="top"> |
|---|
| 168 | <tbody> |
|---|
| 169 | <tr> |
|---|
| 170 | <td> |
|---|
| 171 | <span class="term">Requires:</span></td> |
|---|
| 172 | <td> |
|---|
| 173 | <code class="computeroutput">T</code> must be unambiguously convertible to one of |
|---|
| 174 | the bounded types (i.e., <code class="computeroutput">T1</code>, <code class="computeroutput">T2</code>, |
|---|
| 175 | etc.).</td> |
|---|
| 176 | </tr> |
|---|
| 177 | <tr> |
|---|
| 178 | <td> |
|---|
| 179 | <span class="term">Postconditions:</span></td> |
|---|
| 180 | <td>Content of <code class="computeroutput">*this</code> is the best conversion of |
|---|
| 181 | <code class="computeroutput">operand</code> to one of the bounded types, as determined |
|---|
| 182 | by standard overload resolution rules.</td> |
|---|
| 183 | </tr> |
|---|
| 184 | <tr> |
|---|
| 185 | <td> |
|---|
| 186 | <span class="term">Throws:</span></td> |
|---|
| 187 | <td>May fail with any exceptions arising from the conversion of |
|---|
| 188 | <code class="computeroutput">operand</code> to one of the bounded types.</td> |
|---|
| 189 | </tr> |
|---|
| 190 | </tbody> |
|---|
| 191 | </table></div> |
|---|
| 192 | </li> |
|---|
| 193 | <li> |
|---|
| 194 | <pre class="literallayout"><span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> T> <a name="id1636459-bb"></a>variant(<span class="bold"><strong>const</strong></span> T & operand);</pre> |
|---|
| 195 | <div class="variablelist"><table border="0"> |
|---|
| 196 | <col align="left" valign="top"> |
|---|
| 197 | <tbody><tr> |
|---|
| 198 | <td> |
|---|
| 199 | <span class="term">Notes:</span></td> |
|---|
| 200 | <td>Same semantics as previous constructor, but allows |
|---|
| 201 | construction from temporaries.</td> |
|---|
| 202 | </tr></tbody> |
|---|
| 203 | </table></div> |
|---|
| 204 | </li> |
|---|
| 205 | <li> |
|---|
| 206 | <pre class="literallayout"><span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> U1, <span class="bold"><strong>typename</strong></span> U2, ..., <span class="bold"><strong>typename</strong></span> UN> |
|---|
| 207 | <a name="id1604404-bb"></a>variant(variant<U1, U2, ..., UN> & operand);</pre> |
|---|
| 208 | <div class="variablelist"><table border="0"> |
|---|
| 209 | <col align="left" valign="top"> |
|---|
| 210 | <tbody> |
|---|
| 211 | <tr> |
|---|
| 212 | <td> |
|---|
| 213 | <span class="term">Requires:</span></td> |
|---|
| 214 | <td> |
|---|
| 215 | <span class="emphasis"><em>Every</em></span> one of <code class="computeroutput">U1</code>, |
|---|
| 216 | <code class="computeroutput">U2</code>, ..., <code class="computeroutput">UN</code> must have an unambiguous |
|---|
| 217 | conversion to one of the bounded types (i.e., <code class="computeroutput">T1</code>, |
|---|
| 218 | <code class="computeroutput">T2</code>, ..., <code class="computeroutput">TN</code>).</td> |
|---|
| 219 | </tr> |
|---|
| 220 | <tr> |
|---|
| 221 | <td> |
|---|
| 222 | <span class="term">Postconditions:</span></td> |
|---|
| 223 | <td>If <code class="computeroutput">variant<U1, U2, ..., UN></code> is itself |
|---|
| 224 | one of the bounded types, then content of <code class="computeroutput">*this</code> is a |
|---|
| 225 | copy of <code class="computeroutput">operand</code>. Otherwise, content of |
|---|
| 226 | <code class="computeroutput">*this</code> is the best conversion of the content of |
|---|
| 227 | <code class="computeroutput">operand</code> to one of the bounded types, as determined |
|---|
| 228 | by standard overload resolution rules.</td> |
|---|
| 229 | </tr> |
|---|
| 230 | <tr> |
|---|
| 231 | <td> |
|---|
| 232 | <span class="term">Throws:</span></td> |
|---|
| 233 | <td>If <code class="computeroutput">variant<U1, U2, ..., UN></code> is itself |
|---|
| 234 | one of the bounded types, then may fail with any exceptions arising |
|---|
| 235 | from the copy constructor of |
|---|
| 236 | <code class="computeroutput">variant<U1, U2, ..., UN></code>. Otherwise, may fail |
|---|
| 237 | with any exceptions arising from the conversion of the content of |
|---|
| 238 | <code class="computeroutput">operand</code> to one of the bounded types.</td> |
|---|
| 239 | </tr> |
|---|
| 240 | </tbody> |
|---|
| 241 | </table></div> |
|---|
| 242 | </li> |
|---|
| 243 | <li> |
|---|
| 244 | <pre class="literallayout"><span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> U1, <span class="bold"><strong>typename</strong></span> U2, ..., <span class="bold"><strong>typename</strong></span> UN> |
|---|
| 245 | <a name="id1630438-bb"></a>variant(<span class="bold"><strong>const</strong></span> variant<U1, U2, ..., UN> & operand);</pre> |
|---|
| 246 | <div class="variablelist"><table border="0"> |
|---|
| 247 | <col align="left" valign="top"> |
|---|
| 248 | <tbody><tr> |
|---|
| 249 | <td> |
|---|
| 250 | <span class="term">Notes:</span></td> |
|---|
| 251 | <td>Same semantics as previous constructor, but allows |
|---|
| 252 | construction from temporaries.</td> |
|---|
| 253 | </tr></tbody> |
|---|
| 254 | </table></div> |
|---|
| 255 | </li> |
|---|
| 256 | <li> |
|---|
| 257 | <pre class="literallayout"><a name="id1601741-bb"></a>~variant();</pre> |
|---|
| 258 | <div class="variablelist"><table border="0"> |
|---|
| 259 | <col align="left" valign="top"> |
|---|
| 260 | <tbody> |
|---|
| 261 | <tr> |
|---|
| 262 | <td> |
|---|
| 263 | <span class="term">Effects:</span></td> |
|---|
| 264 | <td>Destroys the content of <code class="computeroutput">*this</code>.</td> |
|---|
| 265 | </tr> |
|---|
| 266 | <tr> |
|---|
| 267 | <td> |
|---|
| 268 | <span class="term">Throws:</span></td> |
|---|
| 269 | <td>Will not throw.</td> |
|---|
| 270 | </tr> |
|---|
| 271 | </tbody> |
|---|
| 272 | </table></div> |
|---|
| 273 | </li> |
|---|
| 274 | </ol></div> |
|---|
| 275 | </div> |
|---|
| 276 | <div class="refsect2" lang="en"> |
|---|
| 277 | <a name="id1945483"></a><h3> |
|---|
| 278 | <a name="id790460-bb"></a><code class="computeroutput">variant</code> modifiers</h3> |
|---|
| 279 | <div class="orderedlist"><ol type="1"> |
|---|
| 280 | <li> |
|---|
| 281 | <pre class="literallayout"><span class="type"><span class="bold"><strong>void</strong></span></span> <a name="id790464-bb"></a>swap(variant & other);</pre> |
|---|
| 282 | <div class="variablelist"><table border="0"> |
|---|
| 283 | <col align="left" valign="top"> |
|---|
| 284 | <tbody> |
|---|
| 285 | <tr> |
|---|
| 286 | <td> |
|---|
| 287 | <span class="term">Requires:</span></td> |
|---|
| 288 | <td>Every bounded type must fulfill the requirements of the |
|---|
| 289 | <a href="../Assignable.html" title="Concept Assignable">Assignable</a> |
|---|
| 290 | concept.</td> |
|---|
| 291 | </tr> |
|---|
| 292 | <tr> |
|---|
| 293 | <td> |
|---|
| 294 | <span class="term">Effects:</span></td> |
|---|
| 295 | <td>Interchanges the content of <code class="computeroutput">*this</code> and |
|---|
| 296 | <code class="computeroutput">other</code>.</td> |
|---|
| 297 | </tr> |
|---|
| 298 | <tr> |
|---|
| 299 | <td> |
|---|
| 300 | <span class="term">Throws:</span></td> |
|---|
| 301 | <td>If the contained type of <code class="computeroutput">other</code> is the same as |
|---|
| 302 | the contained type of <code class="computeroutput">*this</code>, then may fail with any |
|---|
| 303 | exceptions arising from the <code class="computeroutput">swap</code> of the contents of |
|---|
| 304 | <code class="computeroutput">*this</code> and <code class="computeroutput">other</code>. Otherwise, may fail |
|---|
| 305 | with any exceptions arising from either of the copy constructors |
|---|
| 306 | of the contained types. Also, in the event of insufficient |
|---|
| 307 | memory, may fail with <code class="computeroutput">std::bad_alloc</code> |
|---|
| 308 | (<a href="../variant/design.html#variant.design.never-empty.problem" title="The Implementation Problem">why?</a>).</td> |
|---|
| 309 | </tr> |
|---|
| 310 | </tbody> |
|---|
| 311 | </table></div> |
|---|
| 312 | </li> |
|---|
| 313 | <li> |
|---|
| 314 | <pre class="literallayout"><span class="type">variant &</span> <a name="id1669309-bb"></a><span class="bold"><strong>operator</strong></span>=(<span class="bold"><strong>const</strong></span> variant & rhs);</pre> |
|---|
| 315 | <div class="variablelist"><table border="0"> |
|---|
| 316 | <col align="left" valign="top"> |
|---|
| 317 | <tbody> |
|---|
| 318 | <tr> |
|---|
| 319 | <td> |
|---|
| 320 | <span class="term">Requires:</span></td> |
|---|
| 321 | <td>Every bounded type must fulfill the requirements of the |
|---|
| 322 | <a href="../Assignable.html" title="Concept Assignable">Assignable</a> |
|---|
| 323 | concept.</td> |
|---|
| 324 | </tr> |
|---|
| 325 | <tr> |
|---|
| 326 | <td> |
|---|
| 327 | <span class="term">Effects:</span></td> |
|---|
| 328 | <td>If the contained type of <code class="computeroutput">rhs</code> is the same as |
|---|
| 329 | the contained type of <code class="computeroutput">*this</code>, then assigns the |
|---|
| 330 | content of <code class="computeroutput">rhs</code> into the content of |
|---|
| 331 | <code class="computeroutput">*this</code>. Otherwise, makes the content of |
|---|
| 332 | <code class="computeroutput">*this</code> a copy of the content of <code class="computeroutput">rhs</code>, |
|---|
| 333 | destroying the previous content of <code class="computeroutput">*this</code>.</td> |
|---|
| 334 | </tr> |
|---|
| 335 | <tr> |
|---|
| 336 | <td> |
|---|
| 337 | <span class="term">Throws:</span></td> |
|---|
| 338 | <td>If the contained type of <code class="computeroutput">rhs</code> is the same as |
|---|
| 339 | the contained type of <code class="computeroutput">*this</code>, then may fail with any |
|---|
| 340 | exceptions arising from the assignment of the content of |
|---|
| 341 | <code class="computeroutput">rhs</code> into the content <code class="computeroutput">*this</code>. Otherwise, |
|---|
| 342 | may fail with any exceptions arising from the copy constructor |
|---|
| 343 | of the contained type of <code class="computeroutput">rhs</code>. Also, in the event of |
|---|
| 344 | insufficient memory, may fail with <code class="computeroutput">std::bad_alloc</code> |
|---|
| 345 | (<a href="../variant/design.html#variant.design.never-empty.problem" title="The Implementation Problem">why?</a>).</td> |
|---|
| 346 | </tr> |
|---|
| 347 | </tbody> |
|---|
| 348 | </table></div> |
|---|
| 349 | </li> |
|---|
| 350 | <li> |
|---|
| 351 | <pre class="literallayout"><span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> T> <span class="type">variant &</span> <a name="id1634032-bb"></a><span class="bold"><strong>operator</strong></span>=(<span class="bold"><strong>const</strong></span> T & rhs);</pre> |
|---|
| 352 | <div class="variablelist"><table border="0"> |
|---|
| 353 | <col align="left" valign="top"> |
|---|
| 354 | <tbody> |
|---|
| 355 | <tr> |
|---|
| 356 | <td> |
|---|
| 357 | <span class="term">Requires:</span></td> |
|---|
| 358 | <td><div class="itemizedlist"><ul type="disc"> |
|---|
| 359 | <li> |
|---|
| 360 | <code class="computeroutput">T</code> must be unambiguously convertible to |
|---|
| 361 | one of the bounded types (i.e., <code class="computeroutput">T1</code>, |
|---|
| 362 | <code class="computeroutput">T2</code>, etc.).</li> |
|---|
| 363 | <li>Every bounded type must fulfill the requirements of the |
|---|
| 364 | <a href="../Assignable.html" title="Concept Assignable">Assignable</a> |
|---|
| 365 | concept.</li> |
|---|
| 366 | </ul></div></td> |
|---|
| 367 | </tr> |
|---|
| 368 | <tr> |
|---|
| 369 | <td> |
|---|
| 370 | <span class="term">Effects:</span></td> |
|---|
| 371 | <td>If the contained type of <code class="computeroutput">*this</code> is |
|---|
| 372 | <code class="computeroutput">T</code>, then assigns <code class="computeroutput">rhs</code> into the content |
|---|
| 373 | of <code class="computeroutput">*this</code>. Otherwise, makes the content of |
|---|
| 374 | <code class="computeroutput">*this</code> the best conversion of <code class="computeroutput">rhs</code> to |
|---|
| 375 | one of the bounded types, as determined by standard overload |
|---|
| 376 | resolution rules, destroying the previous content of |
|---|
| 377 | <code class="computeroutput">*this</code>.</td> |
|---|
| 378 | </tr> |
|---|
| 379 | <tr> |
|---|
| 380 | <td> |
|---|
| 381 | <span class="term">Throws:</span></td> |
|---|
| 382 | <td>If the contained type of <code class="computeroutput">*this</code> is |
|---|
| 383 | <code class="computeroutput">T</code>, then may fail with any exceptions arising from |
|---|
| 384 | the assignment of <code class="computeroutput">rhs</code> into the content |
|---|
| 385 | <code class="computeroutput">*this</code>. Otherwise, may fail with any exceptions |
|---|
| 386 | arising from the conversion of <code class="computeroutput">rhs</code> to one of the |
|---|
| 387 | bounded types. Also, in the event of insufficient memory, may |
|---|
| 388 | fail with <code class="computeroutput">std::bad_alloc</code> |
|---|
| 389 | (<a href="../variant/design.html#variant.design.never-empty.problem" title="The Implementation Problem">why?</a>).</td> |
|---|
| 390 | </tr> |
|---|
| 391 | </tbody> |
|---|
| 392 | </table></div> |
|---|
| 393 | </li> |
|---|
| 394 | </ol></div> |
|---|
| 395 | </div> |
|---|
| 396 | <div class="refsect2" lang="en"> |
|---|
| 397 | <a name="id1945960"></a><h3> |
|---|
| 398 | <a name="id1572706-bb"></a><code class="computeroutput">variant</code> queries</h3> |
|---|
| 399 | <div class="orderedlist"><ol type="1"> |
|---|
| 400 | <li> |
|---|
| 401 | <pre class="literallayout"><span class="type"><span class="bold"><strong>int</strong></span></span> <a name="id1572710-bb"></a>which() <span class="bold"><strong>const</strong></span>;</pre> |
|---|
| 402 | <div class="variablelist"><table border="0"> |
|---|
| 403 | <col align="left" valign="top"> |
|---|
| 404 | <tbody> |
|---|
| 405 | <tr> |
|---|
| 406 | <td> |
|---|
| 407 | <span class="term">Returns:</span></td> |
|---|
| 408 | <td>The zero-based index into the set of bounded types |
|---|
| 409 | of the contained type of <code class="computeroutput">*this</code>. (For instance, if |
|---|
| 410 | called on a <code class="computeroutput">variant<int, std::string></code> object |
|---|
| 411 | containing a <code class="computeroutput">std::string</code>, <code class="computeroutput">which()</code> |
|---|
| 412 | would return <code class="computeroutput">1</code>.)</td> |
|---|
| 413 | </tr> |
|---|
| 414 | <tr> |
|---|
| 415 | <td> |
|---|
| 416 | <span class="term">Throws:</span></td> |
|---|
| 417 | <td>Will not throw.</td> |
|---|
| 418 | </tr> |
|---|
| 419 | </tbody> |
|---|
| 420 | </table></div> |
|---|
| 421 | </li> |
|---|
| 422 | <li> |
|---|
| 423 | <pre class="literallayout"><span class="type"><span class="bold"><strong>bool</strong></span></span> <a name="id1631554-bb"></a>empty() <span class="bold"><strong>const</strong></span>;</pre> |
|---|
| 424 | <div class="variablelist"><table border="0"> |
|---|
| 425 | <col align="left" valign="top"> |
|---|
| 426 | <tbody> |
|---|
| 427 | <tr> |
|---|
| 428 | <td> |
|---|
| 429 | <span class="term">Returns:</span></td> |
|---|
| 430 | <td> |
|---|
| 431 | <code class="computeroutput">false</code>: <code class="computeroutput">variant</code> always contains |
|---|
| 432 | exactly one of its bounded types. (See |
|---|
| 433 | <a href="../variant/design.html#variant.design.never-empty" title='"Never-Empty" Guarantee'>the section called “"Never-Empty" Guarantee”</a> |
|---|
| 434 | for more information.)</td> |
|---|
| 435 | </tr> |
|---|
| 436 | <tr> |
|---|
| 437 | <td> |
|---|
| 438 | <span class="term">Rationale:</span></td> |
|---|
| 439 | <td>Facilitates generic compatibility with |
|---|
| 440 | <a href="any.html" title="Class any">boost::any</a>.</td> |
|---|
| 441 | </tr> |
|---|
| 442 | <tr> |
|---|
| 443 | <td> |
|---|
| 444 | <span class="term">Throws:</span></td> |
|---|
| 445 | <td>Will not throw.</td> |
|---|
| 446 | </tr> |
|---|
| 447 | </tbody> |
|---|
| 448 | </table></div> |
|---|
| 449 | </li> |
|---|
| 450 | <li> |
|---|
| 451 | <pre class="literallayout"><span class="type"><span class="bold"><strong>const</strong></span> std::type_info &</span> <a name="id1005344-bb"></a>type() <span class="bold"><strong>const</strong></span>;</pre> |
|---|
| 452 | <div class="variablelist"><table border="0"> |
|---|
| 453 | <col align="left" valign="top"> |
|---|
| 454 | <tbody> |
|---|
| 455 | <tr> |
|---|
| 456 | <td> |
|---|
| 457 | <span class="term">Returns:</span></td> |
|---|
| 458 | <td> |
|---|
| 459 | <code class="computeroutput">typeid(x)</code>, where <code class="computeroutput">x</code> is the the |
|---|
| 460 | content of <code class="computeroutput">*this</code>.</td> |
|---|
| 461 | </tr> |
|---|
| 462 | <tr> |
|---|
| 463 | <td> |
|---|
| 464 | <span class="term">Throws:</span></td> |
|---|
| 465 | <td>Will not throw.</td> |
|---|
| 466 | </tr> |
|---|
| 467 | </tbody> |
|---|
| 468 | </table></div> |
|---|
| 469 | </li> |
|---|
| 470 | </ol></div> |
|---|
| 471 | </div> |
|---|
| 472 | <div class="refsect2" lang="en"> |
|---|
| 473 | <a name="id1946192"></a><h3> |
|---|
| 474 | <a name="id1636712-bb"></a><code class="computeroutput">variant</code> relational</h3> |
|---|
| 475 | <div class="orderedlist"><ol type="1"> |
|---|
| 476 | <li> |
|---|
| 477 | <p><a name="id1636716-bb"></a></p> |
|---|
| 478 | <pre class="literallayout"><span class="type"><span class="bold"><strong>bool</strong></span></span> <a name="id1011694-bb"></a><span class="bold"><strong>operator</strong></span>==(<span class="bold"><strong>const</strong></span> variant & rhs) <span class="bold"><strong>const</strong></span>; |
|---|
| 479 | <span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> U> <span class="type"><span class="bold"><strong>void</strong></span></span> <a name="id1673222-bb"></a><span class="bold"><strong>operator</strong></span>==(<span class="bold"><strong>const</strong></span> U &) <span class="bold"><strong>const</strong></span>;</pre> |
|---|
| 480 | <div class="variablelist"><table border="0"> |
|---|
| 481 | <col align="left" valign="top"> |
|---|
| 482 | <tbody> |
|---|
| 483 | <tr> |
|---|
| 484 | <td> |
|---|
| 485 | <span class="term">Notes:</span></td> |
|---|
| 486 | <td>The overload returning <code class="computeroutput">void</code> exists only to |
|---|
| 487 | prohibit implicit conversion of the operator's right-hand side |
|---|
| 488 | to <code class="computeroutput">variant</code>; thus, its use will (purposefully) |
|---|
| 489 | result in a compile-time error.</td> |
|---|
| 490 | </tr> |
|---|
| 491 | <tr> |
|---|
| 492 | <td> |
|---|
| 493 | <span class="term">Requires:</span></td> |
|---|
| 494 | <td>Every bounded type of the <code class="computeroutput">variant</code> must |
|---|
| 495 | fulfill the requirements of the |
|---|
| 496 | <a href="../EqualityComparable.html" title="Concept EqualityComparable">EqualityComparable</a> |
|---|
| 497 | concept.</td> |
|---|
| 498 | </tr> |
|---|
| 499 | <tr> |
|---|
| 500 | <td> |
|---|
| 501 | <span class="term">Returns:</span></td> |
|---|
| 502 | <td> |
|---|
| 503 | <code class="computeroutput">true</code> iff <code class="computeroutput">which() == rhs.which()</code> |
|---|
| 504 | <span class="emphasis"><em>and</em></span> |
|---|
| 505 | <code class="computeroutput">content_this == content_rhs</code>, where |
|---|
| 506 | <code class="computeroutput">content_this</code> is the content of <code class="computeroutput">*this</code> |
|---|
| 507 | and <code class="computeroutput">content_rhs</code> is the content of |
|---|
| 508 | <code class="computeroutput">rhs</code>.</td> |
|---|
| 509 | </tr> |
|---|
| 510 | <tr> |
|---|
| 511 | <td> |
|---|
| 512 | <span class="term">Throws:</span></td> |
|---|
| 513 | <td>If <code class="computeroutput">which() == rhs.which()</code> then may fail with |
|---|
| 514 | any exceptions arising from <code class="computeroutput">operator==(T,T)</code>, where |
|---|
| 515 | <code class="computeroutput">T</code> is the contained type of |
|---|
| 516 | <code class="computeroutput">*this</code>.</td> |
|---|
| 517 | </tr> |
|---|
| 518 | </tbody> |
|---|
| 519 | </table></div> |
|---|
| 520 | </li> |
|---|
| 521 | <li> |
|---|
| 522 | <p><a name="id1638192-bb"></a></p> |
|---|
| 523 | <pre class="literallayout"><span class="type"><span class="bold"><strong>bool</strong></span></span> <a name="id1638199-bb"></a><span class="bold"><strong>operator</strong></span><(<span class="bold"><strong>const</strong></span> variant & rhs) <span class="bold"><strong>const</strong></span>; |
|---|
| 524 | <span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> U> <span class="type"><span class="bold"><strong>void</strong></span></span> <a name="id1638215-bb"></a><span class="bold"><strong>operator</strong></span><(<span class="bold"><strong>const</strong></span> U &) <span class="bold"><strong>const</strong></span>;</pre> |
|---|
| 525 | <div class="variablelist"><table border="0"> |
|---|
| 526 | <col align="left" valign="top"> |
|---|
| 527 | <tbody> |
|---|
| 528 | <tr> |
|---|
| 529 | <td> |
|---|
| 530 | <span class="term">Notes:</span></td> |
|---|
| 531 | <td>The overload returning <code class="computeroutput">void</code> exists only to |
|---|
| 532 | prohibit implicit conversion of the operator's right-hand side |
|---|
| 533 | to <code class="computeroutput">variant</code>; thus, its use will (purposefully) |
|---|
| 534 | result in a compile-time error.</td> |
|---|
| 535 | </tr> |
|---|
| 536 | <tr> |
|---|
| 537 | <td> |
|---|
| 538 | <span class="term">Requires:</span></td> |
|---|
| 539 | <td>Every bounded type of the <code class="computeroutput">variant</code> must |
|---|
| 540 | fulfill the requirements of the |
|---|
| 541 | <a href="../LessThanComparable.html" title="Concept LessThanComparable">LessThanComparable</a> |
|---|
| 542 | concept.</td> |
|---|
| 543 | </tr> |
|---|
| 544 | <tr> |
|---|
| 545 | <td> |
|---|
| 546 | <span class="term">Returns:</span></td> |
|---|
| 547 | <td>If <code class="computeroutput">which() == rhs.which()</code> then: |
|---|
| 548 | <code class="computeroutput">content_this < content_rhs</code>, where |
|---|
| 549 | <code class="computeroutput">content_this</code> is the content of <code class="computeroutput">*this</code> |
|---|
| 550 | and <code class="computeroutput">content_rhs</code> is the content of <code class="computeroutput">rhs</code>. |
|---|
| 551 | Otherwise: <code class="computeroutput">which() < rhs.which()</code>.</td> |
|---|
| 552 | </tr> |
|---|
| 553 | <tr> |
|---|
| 554 | <td> |
|---|
| 555 | <span class="term">Throws:</span></td> |
|---|
| 556 | <td>If <code class="computeroutput">which() == rhs.which()</code> then may fail with |
|---|
| 557 | any exceptions arising from <code class="computeroutput">operator<(T,T)</code>, |
|---|
| 558 | where <code class="computeroutput">T</code> is the contained type of |
|---|
| 559 | <code class="computeroutput">*this</code>.</td> |
|---|
| 560 | </tr> |
|---|
| 561 | </tbody> |
|---|
| 562 | </table></div> |
|---|
| 563 | </li> |
|---|
| 564 | </ol></div> |
|---|
| 565 | </div> |
|---|
| 566 | </div> |
|---|
| 567 | </div> |
|---|
| 568 | <table width="100%"><tr> |
|---|
| 569 | <td align="left"></td> |
|---|
| 570 | <td align="right"><small>Copyright © 2002, 2003 Eric Friedman, Itay Maman</small></td> |
|---|
| 571 | </tr></table> |
|---|
| 572 | <hr> |
|---|
| 573 | <div class="spirit-nav"> |
|---|
| 574 | <a accesskey="p" href="../BOOST_VARIANT_NO_FULL_RECURSIVE_VARIANT_SUPPORT.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../variant/reference.html#header.boost.variant.variant.hpp"><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="../id1599586-bb.html"><img src="../images/next.png" alt="Next"></a> |
|---|
| 575 | </div> |
|---|
| 576 | </body> |
|---|
| 577 | </html> |
|---|