Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/variant/doc/reference/variant.xml @ 29

Last change on this file since 29 was 29, checked in by landauf, 16 years ago

updated boost from 1_33_1 to 1_34_1

File size: 21.8 KB
Line 
1<?xml version="1.0" encoding="utf-8"?>
2<!DOCTYPE header PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
3  "http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
4<header name="boost/variant/variant.hpp">
5  <namespace name="boost">
6    <class name="variant">
7      <purpose>Safe, generic, stack-based discriminated union container.</purpose>
8      <description>
9        <simpara>The <code>variant</code> class template (inspired by Andrei
10        Alexandrescu's class of the same name
11        [<link linkend="variant.refs.ale01a">Ale01A</link>]) is an efficient,
12        <link linkend="variant.tutorial.recursive">recursive-capable</link>,
13        bounded discriminated union value type capable of containing any value
14        type (either POD or non-POD). It supports construction from any type
15        convertible to one of its bounded types or from a source
16        <code>variant</code> whose bounded types are each convertible to one
17        of the destination <code>variant</code>'s bounded types. As well,
18        through <code><functionname>apply_visitor</functionname></code>,
19        <code>variant</code> supports compile-time checked, type-safe
20        visitation; and through <code><functionname>get</functionname></code>,
21        <code>variant</code> supports run-time checked, type-safe value
22        retrieval.</simpara>
23
24        <simpara><emphasis role="bold">Notes</emphasis>:</simpara>
25        <itemizedlist>
26          <listitem>The bounded types of the <code>variant</code> are exposed
27            via the nested typedef <code>types</code>, which is an
28            <libraryname>MPL</libraryname>-compatible Sequence containing the
29            set of types that must be handled by any
30            <link linkend="variant.concepts.static-visitor">visitor</link> to
31            the <code>variant</code>.</listitem>
32          <listitem>All members of <code>variant</code> satisfy at least the
33            basic guarantee of exception-safety. That is, all operations on
34            a <code>variant</code> remain defined even after previous
35            operations have failed.</listitem>
36          <listitem>Each type specified as a template argument to
37            <code>variant</code> must meet the requirements of the
38            <emphasis><link linkend="variant.concepts.bounded-type">BoundedType</link></emphasis>
39            concept.</listitem>
40          <listitem>Each type specified as a template argument to
41            <code>variant</code> must be distinct after removal of qualifiers.
42            Thus, for instance, both <code>variant&lt;int, int&gt;</code> and
43            <code>variant&lt;int, const int&gt;</code> have undefined
44            behavior.</listitem>
45          <listitem>Conforming implementations of <code>variant</code> must
46            allow at least ten types as template arguments. The exact number
47            of allowed arguments is exposed by the preprocessor macro
48            <code><macroname>BOOST_VARIANT_LIMIT_TYPES</macroname></code>.
49            (See <code><classname>make_variant_over</classname></code> for a
50            means to specify the bounded types of a <code>variant</code> by
51            the elements of an <libraryname>MPL</libraryname> or compatible
52            Sequence, thus overcoming this limitation.)</listitem>
53        </itemizedlist>
54      </description>
55
56      <template>
57        <template-type-parameter name="T1"/>
58        <template-type-parameter name="T2">
59          <default><emphasis>unspecified</emphasis></default>
60        </template-type-parameter>
61        <template-varargs/>
62        <template-type-parameter name="TN">
63          <default><emphasis>unspecified</emphasis></default>
64        </template-type-parameter>
65      </template>
66
67      <typedef name="types">
68        <type><emphasis>unspecified</emphasis></type>
69      </typedef>
70
71      <destructor>
72        <effects>
73          <simpara>Destroys the content of <code>*this</code>.</simpara>
74        </effects>
75
76        <throws>Will not throw.</throws>
77      </destructor>
78
79      <constructor>
80        <requires>
81          <simpara>The first bounded type of the <code>variant</code> (i.e.,
82            <code>T1</code>) must fulfill the requirements of the
83            <emphasis>DefaultConstructible</emphasis> [20.1.4]
84            concept.</simpara>
85        </requires>
86
87        <postconditions>
88          <simpara>Content of <code>*this</code> is the default value of the
89            first bounded type (i.e, <code>T1</code>).</simpara>
90        </postconditions>
91
92        <throws>
93          <simpara>May fail with any exceptions arising from the default
94            constructor of <code>T1</code>.</simpara>
95        </throws>
96      </constructor>
97
98      <constructor>
99        <parameter name="other">
100          <paramtype>const variant &amp;</paramtype>
101        </parameter>
102
103        <postconditions>
104          <simpara>Content of <code>*this</code> is a copy of the content of
105            <code>other</code>.</simpara>
106        </postconditions>
107       
108        <throws>
109          <simpara>May fail with any exceptions arising from the
110            copy constructor of <code>other</code>'s contained type.</simpara>
111        </throws>
112      </constructor>
113
114      <constructor>
115        <template>
116          <template-type-parameter name="T"/>
117        </template>
118
119        <parameter name="operand">
120          <paramtype>T &amp;</paramtype>
121        </parameter>
122
123        <requires>
124          <simpara><code>T</code> must be unambiguously convertible to one of
125            the bounded types (i.e., <code>T1</code>, <code>T2</code>,
126            etc.).</simpara>
127        </requires>
128
129        <postconditions>
130          <simpara>Content of <code>*this</code> is the best conversion of
131            <code>operand</code> to one of the bounded types, as determined
132            by standard overload resolution rules.</simpara>
133        </postconditions>
134
135        <throws>
136          <simpara>May fail with any exceptions arising from the conversion of
137            <code>operand</code> to one of the bounded types.</simpara>
138        </throws>
139      </constructor>
140
141      <constructor>
142        <template>
143          <template-type-parameter name="T"/>
144        </template>
145
146        <parameter name="operand">
147          <paramtype>const T &amp;</paramtype>
148        </parameter>
149
150        <notes>
151          <simpara>Same semantics as previous constructor, but allows
152            construction from temporaries.</simpara>
153        </notes>
154      </constructor>
155
156      <constructor>
157        <template>
158          <template-type-parameter name="U1"/>
159          <template-type-parameter name="U2"/>
160          <template-varargs/>
161          <template-type-parameter name="UN"/>
162        </template>
163
164        <parameter name="operand">
165          <paramtype>variant&lt;U1, U2, ..., UN&gt; &amp;</paramtype>
166        </parameter>
167
168        <requires>
169          <simpara><emphasis>Every</emphasis> one of <code>U1</code>,
170            <code>U2</code>, ..., <code>UN</code> must have an unambiguous
171            conversion to one of the bounded types (i.e., <code>T1</code>,
172            <code>T2</code>, ..., <code>TN</code>).</simpara>
173        </requires>
174
175        <postconditions>
176          <simpara>If <code>variant&lt;U1, U2, ..., UN&gt;</code> is itself
177            one of the bounded types, then content of <code>*this</code> is a
178            copy of <code>operand</code>. Otherwise, content of
179            <code>*this</code> is the best conversion of the content of
180            <code>operand</code> to one of the bounded types, as determined
181            by standard overload resolution rules.</simpara>
182        </postconditions>
183
184        <throws>
185          <simpara>If <code>variant&lt;U1, U2, ..., UN&gt;</code> is itself
186          one of the bounded types, then may fail with any exceptions arising
187          from the copy constructor of
188          <code>variant&lt;U1, U2, ..., UN&gt;</code>. Otherwise, may fail
189          with any exceptions arising from the conversion of the content of
190          <code>operand</code> to one of the bounded types.</simpara>
191        </throws>
192      </constructor>
193     
194      <constructor>
195        <template>
196          <template-type-parameter name="U1"/>
197          <template-type-parameter name="U2"/>
198          <template-varargs/>
199          <template-type-parameter name="UN"/>
200        </template>
201
202        <parameter name="operand">
203          <paramtype>const variant&lt;U1, U2, ..., UN&gt; &amp;</paramtype>
204        </parameter>
205
206        <notes>
207          <simpara>Same semantics as previous constructor, but allows
208            construction from temporaries.</simpara>
209        </notes>
210      </constructor>
211
212      <method-group name="modifiers">
213
214        <method name="swap">
215          <type>void</type>
216
217          <parameter name="other">
218            <paramtype>variant &amp;</paramtype>
219          </parameter>
220
221          <requires>
222            <simpara>Every bounded type must fulfill the requirements of the
223              <conceptname>Assignable</conceptname>
224              concept.</simpara>
225          </requires>
226
227          <effects>
228            <simpara>Interchanges the content of <code>*this</code> and
229              <code>other</code>.</simpara>
230          </effects>
231
232          <throws>
233            <simpara>If the contained type of <code>other</code> is the same as
234              the contained type of <code>*this</code>, then may fail with any
235              exceptions arising from the <code>swap</code> of the contents of
236              <code>*this</code> and <code>other</code>. Otherwise, may fail
237              with any exceptions arising from either of the copy constructors
238              of the contained types. Also, in the event of insufficient
239              memory, may fail with <code>std::bad_alloc</code>
240              (<link linkend="variant.design.never-empty.problem">why?</link>).</simpara>
241          </throws>
242        </method>
243
244        <method name="operator=">
245          <type>variant &amp;</type>
246
247          <parameter name="rhs">
248            <paramtype>const variant &amp;</paramtype>
249          </parameter>
250
251          <requires>
252            <simpara>Every bounded type must fulfill the requirements of the
253              <conceptname>Assignable</conceptname>
254              concept.</simpara>
255          </requires>
256
257          <effects>
258            <simpara>If the contained type of <code>rhs</code> is the same as
259              the contained type of <code>*this</code>, then assigns the
260              content of <code>rhs</code> into the content of
261              <code>*this</code>. Otherwise, makes the content of
262              <code>*this</code> a copy of the content of <code>rhs</code>,
263              destroying the previous content of <code>*this</code>.</simpara>
264          </effects>
265
266          <throws>
267            <simpara>If the contained type of <code>rhs</code> is the same as
268              the contained type of <code>*this</code>, then may fail with any
269              exceptions arising from the assignment of the content of
270              <code>rhs</code> into the content <code>*this</code>. Otherwise,
271              may fail with any exceptions arising from the copy constructor
272              of the contained type of <code>rhs</code>. Also, in the event of
273              insufficient memory, may fail with <code>std::bad_alloc</code>
274              (<link linkend="variant.design.never-empty.problem">why?</link>).</simpara>
275          </throws>
276        </method>
277
278        <method name="operator=">
279          <type>variant &amp;</type>
280
281          <template>
282            <template-type-parameter name="T"/>
283          </template>
284
285          <parameter name="rhs">
286            <paramtype>const T &amp;</paramtype>
287          </parameter>
288
289          <requires>
290            <itemizedlist>
291              <listitem><code>T</code> must be unambiguously convertible to
292                one of the bounded types (i.e., <code>T1</code>,
293                <code>T2</code>, etc.).</listitem>
294              <listitem>Every bounded type must fulfill the requirements of the
295                <conceptname>Assignable</conceptname>
296                concept.</listitem>
297            </itemizedlist>
298          </requires>
299
300          <effects>
301            <simpara>If the contained type of <code>*this</code> is
302              <code>T</code>, then assigns <code>rhs</code> into the content
303              of <code>*this</code>. Otherwise, makes the content of
304              <code>*this</code> the best conversion of <code>rhs</code> to
305              one of the bounded types, as determined by standard overload
306              resolution rules, destroying the previous content of
307              <code>*this</code>.</simpara>
308          </effects>
309
310          <throws>
311            <simpara>If the contained type of <code>*this</code> is
312              <code>T</code>, then may fail with any exceptions arising from
313              the assignment of <code>rhs</code> into the content
314              <code>*this</code>. Otherwise, may fail with any exceptions
315              arising from the conversion of <code>rhs</code> to one of the
316              bounded types. Also, in the event of insufficient memory, may
317              fail with <code>std::bad_alloc</code>
318              (<link linkend="variant.design.never-empty.problem">why?</link>).</simpara>
319          </throws>
320        </method>
321
322      </method-group>
323
324      <method-group name="queries">
325
326        <method name="which" cv="const">
327          <type>int</type>
328
329          <returns>
330            <simpara>The zero-based index into the set of bounded types
331              of the contained type of <code>*this</code>. (For instance, if
332              called on a <code>variant&lt;int, std::string&gt;</code> object
333              containing a <code>std::string</code>, <code>which()</code>
334              would return <code>1</code>.)</simpara>
335          </returns>
336
337          <throws>Will not throw.</throws>
338        </method>
339
340        <method name="empty" cv="const">
341          <type>bool</type>
342
343          <returns>
344            <simpara><code>false</code>: <code>variant</code> always contains
345              exactly one of its bounded types. (See
346              <xref linkend="variant.design.never-empty"/>
347              for more information.)</simpara>
348          </returns>
349
350          <rationale>
351            <simpara>Facilitates generic compatibility with
352              <classname>boost::any</classname>.</simpara>
353          </rationale>
354
355          <throws>Will not throw.</throws>
356        </method>
357
358        <method name="type" cv="const">
359          <type>const std::type_info &amp;</type>
360
361          <returns>
362            <simpara><code>typeid(x)</code>, where <code>x</code> is the the
363              content of <code>*this</code>.</simpara>
364          </returns>
365
366          <throws>Will not throw.</throws>
367        </method>
368
369      </method-group>
370     
371      <method-group name="relational">
372
373        <overloaded-method name="operator==" cv="const">
374          <purpose>Equality comparison.</purpose>
375
376          <signature cv="const">
377            <type>bool</type>
378            <parameter name="rhs">
379              <paramtype>const variant &amp;</paramtype>
380            </parameter>
381          </signature>
382         
383          <signature cv="const">
384            <type>void</type>
385            <template>
386              <template-type-parameter name="U"/>
387            </template>
388            <parameter>
389              <paramtype>const U &amp;</paramtype>
390            </parameter>
391          </signature>
392
393          <notes>
394            <simpara>The overload returning <code>void</code> exists only to
395              prohibit implicit conversion of the operator's right-hand side
396              to <code>variant</code>; thus, its use will (purposefully)
397              result in a compile-time error.</simpara>
398          </notes>
399
400          <requires>
401            <simpara>Every bounded type of the <code>variant</code> must
402              fulfill the requirements of the
403              <conceptname>EqualityComparable</conceptname>
404              concept.</simpara>
405          </requires>
406
407          <returns>
408            <simpara><code>true</code> iff <code>which() == rhs.which()</code>
409              <emphasis>and</emphasis>
410              <code>content_this == content_rhs</code>, where
411              <code>content_this</code> is the content of <code>*this</code>
412              and <code>content_rhs</code> is the content of
413              <code>rhs</code>.</simpara>
414          </returns>
415         
416          <throws>
417            <simpara>If <code>which() == rhs.which()</code> then may fail with
418              any exceptions arising from <code>operator==(T,T)</code>, where
419              <code>T</code> is the contained type of
420              <code>*this</code>.</simpara>
421          </throws>
422        </overloaded-method>
423
424        <overloaded-method name="operator&lt;">
425          <purpose>LessThan comparison.</purpose>
426
427          <signature cv="const">
428            <type>bool</type>
429            <parameter name="rhs">
430              <paramtype>const variant &amp;</paramtype>
431            </parameter>
432          </signature>
433         
434          <signature cv="const">
435            <type>void</type>
436            <template>
437              <template-type-parameter name="U"/>
438            </template>
439            <parameter>
440              <paramtype>const U &amp;</paramtype>
441            </parameter>
442          </signature>
443
444          <notes>
445            <simpara>The overload returning <code>void</code> exists only to
446              prohibit implicit conversion of the operator's right-hand side
447              to <code>variant</code>; thus, its use will (purposefully)
448              result in a compile-time error.</simpara>
449          </notes>
450
451          <requires>
452            <simpara>Every bounded type of the <code>variant</code> must
453              fulfill the requirements of the
454              <conceptname>LessThanComparable</conceptname>
455              concept.</simpara>
456          </requires>
457
458          <returns>
459            <simpara>If <code>which() == rhs.which()</code> then:
460              <code>content_this &lt; content_rhs</code>, where
461              <code>content_this</code> is the content of <code>*this</code>
462              and <code>content_rhs</code> is the content of <code>rhs</code>.
463              Otherwise: <code>which() &lt; rhs.which()</code>.</simpara>
464          </returns>
465
466          <throws>
467            <simpara>If <code>which() == rhs.which()</code> then may fail with
468              any exceptions arising from <code>operator&lt;(T,T)</code>,
469              where <code>T</code> is the contained type of
470              <code>*this</code>.</simpara>
471          </throws>
472        </overloaded-method>
473
474      </method-group>
475    </class>
476
477    <function name="swap">
478      <template>
479        <template-type-parameter name="T1"/>
480        <template-type-parameter name="T2"/>
481        <template-varargs/>
482        <template-type-parameter name="TN"/>
483      </template>
484
485      <type>void</type>
486
487      <parameter name="lhs">
488        <paramtype><classname>variant</classname>&lt;T1, T2, ..., TN&gt; &amp;</paramtype>
489      </parameter>
490
491      <parameter name="rhs">
492        <paramtype><classname>variant</classname>&lt;T1, T2, ..., TN&gt; &amp;</paramtype>
493      </parameter>
494
495      <effects>
496        <simpara>Swaps <code>lhs</code> with <code>rhs</code> by application
497          of <code><methodname>variant::swap</methodname></code>.</simpara>
498      </effects>
499
500      <throws>
501        <simpara>May fail with any exception arising from
502          <code><methodname>variant::swap</methodname></code>.</simpara>
503      </throws>
504    </function>
505
506    <function name="operator&lt;&lt;">
507      <purpose>Provides streaming output for <code>variant</code> types.</purpose>
508
509      <template>
510        <template-type-parameter name="ElemType"/>
511        <template-type-parameter name="Traits"/>
512        <template-type-parameter name="T1"/>
513        <template-type-parameter name="T2"/>
514        <template-varargs/>
515        <template-type-parameter name="TN"/>
516      </template>
517
518      <type>std::basic_ostream&lt;ElemType,Traits&gt; &amp;</type>
519
520      <parameter name="out">
521        <paramtype>std::basic_ostream&lt;ElemType,Traits&gt; &amp;</paramtype>
522      </parameter>
523
524      <parameter name="rhs">
525        <paramtype>const <classname>variant</classname>&lt;T1, T2, ..., TN&gt; &amp;</paramtype>
526      </parameter>
527
528      <requires>
529        <simpara>Every bounded type of the <code>variant</code> must
530          fulfill the requirements of the
531          <link linkend="variant.concepts.output-streamable"><emphasis>OutputStreamable</emphasis></link>
532          concept.</simpara>
533      </requires>
534
535      <effects>
536        <simpara>Calls <code>out &lt;&lt; x</code>, where <code>x</code> is
537          the content of <code>rhs</code>.</simpara>
538      </effects>
539    </function>
540   
541    <class name="make_variant_over">
542      <purpose>
543        <simpara>Exposes a <code>variant</code> whose bounded types are the
544          elements of the given type sequence.</simpara>
545      </purpose>
546
547      <template>
548        <template-type-parameter name="Sequence"/>
549      </template>
550
551      <typedef name="type">
552        <type>variant&lt; <emphasis>unspecified</emphasis> &gt;</type>
553      </typedef>
554
555      <description>
556        <simpara><code>type</code> has behavior equivalent in every respect to
557          <code><classname>variant</classname>&lt; Sequence[0], Sequence[1], ... &gt;</code>
558          (where <code>Sequence[<emphasis>i</emphasis>]</code> denotes the
559          <emphasis>i</emphasis>-th element of <code>Sequence</code>), except
560          that no upper limit is imposed on the number of types.</simpara>
561
562        <simpara><emphasis role="bold">Notes</emphasis>:</simpara>
563        <itemizedlist>
564          <listitem><code>Sequence</code> must meet the requirements of
565            <libraryname>MPL</libraryname>'s <emphasis>Sequence</emphasis>
566            concept.</listitem>
567          <listitem>Due to standard conformance problems in several compilers,
568            <code>make_variant_over</code> may not be supported on your
569            compiler. See
570            <code><macroname>BOOST_VARIANT_NO_TYPE_SEQUENCE_SUPPORT</macroname></code>
571            for more information.</listitem>
572        </itemizedlist>
573      </description>
574    </class>
575  </namespace>
576</header>
Note: See TracBrowser for help on using the repository browser.