variant.reference.html 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Reference</title><link rel="stylesheet" href="reference.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.61.3"><link rel="home" href="index.html" title="The Boost C++ Libraries"><link rel="up" href="variant.html" title="Boost.Variant"><link rel="previous" href="variant.tutorial.html" title="Tutorial"><link rel="next" href="BOOST_VARIANT_LIMIT_TYPES.html" title="Macro BOOST_VARIANT_LIMIT_TYPES"><link rel="chapter" href="libraries.html" title="The Boost C++ Libraries"><link rel="chapter" href="any.html" title="Boost.Any"><link rel="refentry" href="class.boost.bad_any_cast.html" title="Class bad_any_cast"><link rel="refentry" href="class.boost.any.html" title="Class any"><link rel="refentry" href="id2383300-bb.html" title="Function any_cast"><link rel="chapter" href="array.html" title="Boost.Array"><link rel="refentry" href="class.boost.array.html" title="Class template array"><link rel="chapter" href="function.html" title="Boost.Function"><link rel="refentry" href="class.boost.bad_function_call.html" title="Class bad_function_call"><link rel="refentry" href="class.boost.function_base.html" title="Class function_base"><link rel="refentry" href="class.boost.functionN.html" title="Class template functionN"><link rel="refentry" href="class.boost.function.html" title="Class template function"><link rel="chapter" href="ref.html" title="Boost.Ref"><link rel="refentry" href="class.boost.reference_wrapper.html" title="Class template reference_wrapper"><link rel="refentry" href="class.boost.is_reference_wrapper.html" title="Class template is_reference_wrapper"><link rel="refentry" href="class.boost.unwrap_reference.html" title="Class template unwrap_reference"><link rel="chapter" href="signals.html" title="Boost.Signals"><link rel="refentry" href="class.boost.signalN.html" title="Class template signalN"><link rel="refentry" href="class.boost.signal.html" title="Class template signal"><link rel="refentry" href="class.boost.slot.html" title="Class template slot"><link rel="refentry" href="class.boost.signals.trackable.html" title="Class trackable"><link rel="refentry" href="class.boost.signals.connection.html" title="Class connection"><link rel="refentry" href="class.boost.signals.scoped_connection.html" title="Class scoped_connection"><link rel="refentry" href="id2532119-bb.html" title="Function template visit_each"><link rel="refentry" href="class.boost.last_value.html" title="Class template last_value"><link rel="refentry" href="id2354683-bb.html" title="Class last_value&lt;void&gt;"><link rel="chapter" href="variant.html" title="Boost.Variant"><link rel="refentry" href="BOOST_VARIANT_LIMIT_TYPES.html" title="Macro BOOST_VARIANT_LIMIT_TYPES"><link rel="refentry" href="BOOST_VARIANT_ENUM_PARAMS.html" title="Macro BOOST_VARIANT_ENUM_PARAMS"><link rel="refentry" href="BOOST_VARIANT_ENUM_SHIFTED_PARAMS.html" title="Macro BOOST_VARIANT_ENUM_SHIFTED_PARAMS"><link rel="refentry" href="BOOST_VARIANT_NO_REFERENCE_SUPPORT.html" title="Macro BOOST_VARIANT_NO_REFERENCE_SUPPORT"><link rel="refentry" href="BOOST_VARIANT_NO_TYPE_SEQUENCE_SUPPORT.html" title="Macro BOOST_VARIANT_NO_TYPE_SEQUENCE_SUPPORT"><link rel="refentry" href="BOOST_VARIANT_NO_FULL_RECURSIVE_VARIANT_SUPPORT.html" title="Macro BOOST_VARIANT_NO_FULL_RECURSIVE_VARIANT_SUPPORT"><link rel="refentry" href="class.boost.variant.html" title="Class template variant"><link rel="refentry" href="id2518553-bb.html" title="Function template swap"><link rel="refentry" href="id2524211-bb.html" title="Function template operator&lt;&lt;"><link rel="refentry" href="class.boost.make_variant_over.html" title="Class template make_variant_over"><link rel="refentry" href="class.boost.make_recursive_variant.html" title="Class template make_recursive_variant"><link rel="refentry" href="class.boost.make_recursive_variant_over.html" title="Class template make_recursive_variant_over"><link rel="refentry" href="class.boost.recursive_wrapper.html" title="Class template recursive_wrapper"><link rel="refentry" href="class.boost.is_recursive_wrapper.html" title="Class template is_recursive_wrapper"><link rel="refentry" href="class.boost.unwrap_recursive_wrapper.html" title="Class template unwrap_recursive_wrapper"><link rel="refentry" href="class.boost.apply_visitor_delayed_t.html" title="Class template apply_visitor_delayed_t"><link rel="refentry" href="id2557051-bb.html" title="Function apply_visitor"><link rel="refentry" href="class.boost.bad_get.html" title="Class bad_get"><link rel="refentry" href="id2493238-bb.html" title="Function get"><link rel="refentry" href="class.boost.bad_visit.html" title="Class bad_visit"><link rel="refentry" href="class.boost.static_visitor.html" title="Class template static_visitor"><link rel="refentry" href="class.boost.visitor_ptr_t.html" title="Class template visitor_ptr_t"><link rel="refentry" href="id2544445-bb.html" title="Function template visitor_ptr"><link rel="chapter" href="boostbook.html" title="The BoostBook Documentation Format"><link rel="refentry" href="boostbook.dtd.class-specialization.html" title="
  2. BoostBook element class-specialization"><link rel="refentry" href="boostbook.dtd.link-test.html" title="
  3. BoostBook element link-test"><link rel="refentry" href="boostbook.dtd.link-fail-test.html" title="
  4. BoostBook element link-fail-test"><link rel="refentry" href="boostbook.dtd.typedef.html" title="
  5. BoostBook element typedef"><link rel="refentry" href="boostbook.dtd.static-constant.html" title="
  6. BoostBook element static-constant"><link rel="refentry" href="boostbook.dtd.code.html" title="
  7. BoostBook element code"><link rel="refentry" href="boostbook.dtd.destructor.html" title="
  8. BoostBook element destructor"><link rel="refentry" href="boostbook.dtd.template-type-parameter.html" title="
  9. BoostBook element template-type-parameter"><link rel="refentry" href="boostbook.dtd.description.html" title="
  10. BoostBook element description"><link rel="refentry" href="boostbook.dtd.librarylist.html" title="
  11. BoostBook element librarylist"><link rel="refentry" href="boostbook.dtd.library-reference.html" title="
  12. BoostBook element library-reference"><link rel="refentry" href="boostbook.dtd.boostbook.html" title="
  13. BoostBook element boostbook"><link rel="refentry" href="boostbook.dtd.union.html" title="
  14. BoostBook element union"><link rel="refentry" href="boostbook.dtd.inherit.html" title="
  15. BoostBook element inherit"><link rel="refentry" href="boostbook.dtd.template-varargs.html" title="
  16. BoostBook element template-varargs"><link rel="refentry" href="boostbook.dtd.source.html" title="
  17. BoostBook element source"><link rel="refentry" href="boostbook.dtd.function.html" title="
  18. BoostBook element function"><link rel="refentry" href="boostbook.dtd.postconditions.html" title="
  19. BoostBook element postconditions"><link rel="refentry" href="boostbook.dtd.compile-test.html" title="
  20. BoostBook element compile-test"><link rel="refentry" href="boostbook.dtd.method.html" title="
  21. BoostBook element method"><link rel="refentry" href="boostbook.dtd.snippet.html" title="
  22. BoostBook element snippet"><link rel="refentry" href="boostbook.dtd.constructor.html" title="
  23. BoostBook element constructor"><link rel="refentry" href="boostbook.dtd.namespace.html" title="
  24. BoostBook element namespace"><link rel="refentry" href="boostbook.dtd.if-fails.html" title="
  25. BoostBook element if-fails"><link rel="refentry" href="boostbook.dtd.free-function-group.html" title="
  26. BoostBook element free-function-group"><link rel="refentry" href="boostbook.dtd.functionname.html" title="
  27. BoostBook element functionname"><link rel="refentry" href="boostbook.dtd.librarycategory.html" title="
  28. BoostBook element librarycategory"><link rel="refentry" href="boostbook.dtd.notes.html" title="
  29. BoostBook element notes"><link rel="refentry" href="boostbook.dtd.data-member.html" title="
  30. BoostBook element data-member"><link rel="refentry" href="boostbook.dtd.specialization.html" title="
  31. BoostBook element specialization"><link rel="refentry" href="boostbook.dtd.union-specialization.html" title="
  32. BoostBook element union-specialization"><link rel="refentry" href="boostbook.dtd.throws.html" title="
  33. BoostBook element throws"><link rel="refentry" href="boostbook.dtd.template-arg.html" title="
  34. BoostBook element template-arg"><link rel="refentry" href="boostbook.dtd.method-group.html" title="
  35. BoostBook element method-group"><link rel="refentry" href="boostbook.dtd.requirement.html" title="
  36. BoostBook element requirement"><link rel="refentry" href="boostbook.dtd.precondition.html" title="
  37. BoostBook element precondition"><link rel="refentry" href="boostbook.dtd.paramtype.html" title="
  38. BoostBook element paramtype"><link rel="refentry" href="boostbook.dtd.using-class.html" title="
  39. BoostBook element using-class"><link rel="refentry" href="boostbook.dtd.run-test.html" title="
  40. BoostBook element run-test"><link rel="refentry" href="boostbook.dtd.librarypurpose.html" title="
  41. BoostBook element librarypurpose"><link rel="refentry" href="boostbook.dtd.copy-assignment.html" title="
  42. BoostBook element copy-assignment"><link rel="refentry" href="boostbook.dtd.run-fail-test.html" title="
  43. BoostBook element run-fail-test"><link rel="refentry" href="boostbook.dtd.template.html" title="
  44. BoostBook element template"><link rel="refentry" href="boostbook.dtd.compile-fail-test.html" title="
  45. BoostBook element compile-fail-test"><link rel="refentry" href="boostbook.dtd.returns.html" title="
  46. BoostBook element returns"><link rel="refentry" href="boostbook.dtd.default.html" title="
  47. BoostBook element default"><link rel="refentry" href="boostbook.dtd.parameter.html" title="
  48. BoostBook element parameter"><link rel="refentry" href="boostbook.dtd.signature.html" title="
  49. BoostBook element signature"><link rel="refentry" href="boostbook.dtd.overloaded-function.html" title="
  50. BoostBook element overloaded-function"><link rel="refentry" href="boostbook.dtd.class.html" title="
  51. BoostBook element class"><link rel="refentry" href="boostbook.dtd.librarycategorydef.html" title="
  52. BoostBook element librarycategorydef"><link rel="refentry" href="boostbook.dtd.type.html" title="
  53. BoostBook element type"><link rel="refentry" href="boostbook.dtd.enumvalue.html" title="
  54. BoostBook element enumvalue"><link rel="refentry" href="boostbook.dtd.overloaded-method.html" title="
  55. BoostBook element overloaded-method"><link rel="refentry" href="boostbook.dtd.programlisting.html" title="
  56. BoostBook element programlisting"><link rel="refentry" href="boostbook.dtd.complexity.html" title="
  57. BoostBook element complexity"><link rel="refentry" href="boostbook.dtd.purpose.html" title="
  58. BoostBook element purpose"><link rel="refentry" href="boostbook.dtd.template-nontype-parameter.html" title="
  59. BoostBook element template-nontype-parameter"><link rel="refentry" href="boostbook.dtd.library.html" title="
  60. BoostBook element library"><link rel="refentry" href="boostbook.dtd.librarycategorylist.html" title="
  61. BoostBook element librarycategorylist"><link rel="refentry" href="boostbook.dtd.using-namespace.html" title="
  62. BoostBook element using-namespace"><link rel="refentry" href="boostbook.dtd.struct-specialization.html" title="
  63. BoostBook element struct-specialization"><link rel="refentry" href="boostbook.dtd.struct.html" title="
  64. BoostBook element struct"><link rel="refentry" href="boostbook.dtd.lib.html" title="
  65. BoostBook element lib"><link rel="refentry" href="boostbook.dtd.enum.html" title="
  66. BoostBook element enum"><link rel="refentry" href="boostbook.dtd.requires.html" title="
  67. BoostBook element requires"><link rel="refentry" href="boostbook.dtd.effects.html" title="
  68. BoostBook element effects"><link rel="refentry" href="boostbook.dtd.libraryname.html" title="
  69. BoostBook element libraryname"><link rel="refentry" href="boostbook.dtd.libraryinfo.html" title="
  70. BoostBook element libraryinfo"><link rel="refentry" href="boostbook.dtd.testsuite.html" title="
  71. BoostBook element testsuite"><link rel="refentry" href="boostbook.dtd.header.html" title="
  72. BoostBook element header"><link rel="refentry" href="boostbook.dtd.rationale.html" title="
  73. BoostBook element rationale"><link rel="refentry" href="Assignable.html" title="Concept Assignable"><link rel="refentry" href="InputIterator.html" title="Concept InputIterator"><link rel="refentry" href="OutputIterator.html" title="Concept OutputIterator"><link rel="refentry" href="ForwardIterator.html" title="Concept ForwardIterator"><link rel="refentry" href="BidirectionalIterator.html" title="Concept BidirectionalIterator"><link rel="refentry" href="RandomAccessIterator.html" title="Concept RandomAccessIterator"><link rel="refentry" href="DefaultConstructible.html" title="Concept DefaultConstructible"><link rel="refentry" href="CopyConstructible.html" title="Concept CopyConstructible"><link rel="refentry" href="EqualityComparable.html" title="Concept EqualityComparable"><link rel="refentry" href="LessThanComparable.html" title="Concept LessThanComparable"><link rel="refentry" href="SignedInteger.html" title="Concept SignedInteger"><link rel="subsection" href="variant.reference.html#variant.concepts" title="Concepts"><link rel="subsection" href="variant.reference.html#header.boost.variant.hpp" title="Header &lt;boost/variant.hpp&gt;"><link rel="subsection" href="variant.reference.html#header.boost.variant.variant_fwd.hpp" title="Header &lt;boost/variant/variant_fwd.hpp&gt;"><link rel="subsection" href="variant.reference.html#header.boost.variant.variant.hpp" title="Header &lt;boost/variant/variant.hpp&gt;"><link rel="subsection" href="variant.reference.html#header.boost.variant.recursive_variant.hpp" title="Header &lt;boost/variant/recursive_variant.hpp&gt;"><link rel="subsection" href="variant.reference.html#header.boost.variant.recursive_wrapper.hpp" title="Header &lt;boost/variant/recursive_wrapper.hpp&gt;"><link rel="subsection" href="variant.reference.html#header.boost.variant.apply_visitor.hpp" title="Header &lt;boost/variant/apply_visitor.hpp&gt;"><link rel="subsection" href="variant.reference.html#header.boost.variant.get.hpp" title="Header &lt;boost/variant/get.hpp&gt;"><link rel="subsection" href="variant.reference.html#header.boost.variant.bad_visit.hpp" title="Header &lt;boost/variant/bad_visit.hpp&gt;"><link rel="subsection" href="variant.reference.html#header.boost.variant.static_visitor.hpp" title="Header &lt;boost/variant/static_visitor.hpp&gt;"><link rel="subsection" href="variant.reference.html#header.boost.variant.visitor_ptr.hpp" title="Header &lt;boost/variant/visitor_ptr.hpp&gt;"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" border="1" cellpadding="2" bgcolor="#007F7F"><tr><td bgcolor="#FFFFFF"><img src="../../c++boost.gif" alt="c++boost.gif (8819 bytes)" width="277" height="86"></td><td><a href="../../index.htm"><font color="#FFFFFF" size="4" face="Arial">Home</font></a></td><td><a href="libraries.html"><font color="#FFFFFF" size="4" face="Arial">Libraries</font></a></td><td><a href="../../people/people.htm"><font color="#FFFFFF" size="4" face="Arial">People</font></a></td><td><a href="../../more/faq.htm"><font color="#FFFFFF" size="4" face="Arial">FAQ</font></a></td><td><a href="../../more/index.htm"><font color="#FFFFFF" size="4" face="Arial">More</font></a></td></tr></table><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="variant.reference"></a>Reference</h3></div></div><div></div></div><div class="toc"><dl><dt><a href="variant.reference.html#variant.concepts">Concepts</a></dt><dt><a href="variant.reference.html#header.boost.variant.hpp">Header &lt;boost/variant.hpp&gt;</a></dt><dt><a href="variant.reference.html#header.boost.variant.variant_fwd.hpp">Header &lt;boost/variant/variant_fwd.hpp&gt;</a></dt><dt><a href="variant.reference.html#header.boost.variant.variant.hpp">Header &lt;boost/variant/variant.hpp&gt;</a></dt><dt><a href="variant.reference.html#header.boost.variant.recursive_variant.hpp">Header &lt;boost/variant/recursive_variant.hpp&gt;</a></dt><dt><a href="variant.reference.html#header.boost.variant.recursive_wrapper.hpp">Header &lt;boost/variant/recursive_wrapper.hpp&gt;</a></dt><dt><a href="variant.reference.html#header.boost.variant.apply_visitor.hpp">Header &lt;boost/variant/apply_visitor.hpp&gt;</a></dt><dt><a href="variant.reference.html#header.boost.variant.get.hpp">Header &lt;boost/variant/get.hpp&gt;</a></dt><dt><a href="variant.reference.html#header.boost.variant.bad_visit.hpp">Header &lt;boost/variant/bad_visit.hpp&gt;</a></dt><dt><a href="variant.reference.html#header.boost.variant.static_visitor.hpp">Header &lt;boost/variant/static_visitor.hpp&gt;</a></dt><dt><a href="variant.reference.html#header.boost.variant.visitor_ptr.hpp">Header &lt;boost/variant/visitor_ptr.hpp&gt;</a></dt></dl></div><div class="section" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="variant.concepts"></a>Concepts</h4></div></div><div></div></div><div class="toc"><dl><dt><a href="variant.reference.html#variant.concepts.bounded-type">BoundedType</a></dt><dt><a href="variant.reference.html#variant.concepts.static-visitor">StaticVisitor</a></dt><dt><a href="variant.reference.html#variant.concepts.output-streamable">OutputStreamable</a></dt></dl></div><div class="section" lang="en"><div class="titlepage"><div><div><h5 class="title"><a name="variant.concepts.bounded-type"></a><span class="emphasis"><em>BoundedType</em></span></h5></div></div><div></div></div><p>The requirements on a <span class="bold"><b>bounded type</b></span>
  74. are as follows:</p><div class="itemizedlist"><ul type="disc"><li><a href="CopyConstructible.html" title="Concept CopyConstructible">CopyConstructible</a> [20.1.3].</li><li>Destructor upholds the no-throw exception-safety
  75. guarantee.</li><li>Complete at the point of <tt class="computeroutput">variant</tt> template
  76. instantiation. (See
  77. <tt class="computeroutput"><a href="class.boost.recursive_wrapper.html" title="Class template recursive_wrapper">boost::recursive_wrapper</a>&lt;T&gt;</tt>
  78. for a type wrapper that accepts incomplete types to enable recursive
  79. <tt class="computeroutput">variant</tt> types.)</li></ul></div><p>Every type specified as a template argument to
  80. <tt class="computeroutput"><a href="class.boost.variant.html" title="Class template variant">variant</a></tt> must at minimum fulfill the
  81. above requirements. In addition, certain features of <tt class="computeroutput">variant</tt>
  82. are available only if its bounded types meet the requirements of these
  83. following additional concepts:</p><div class="itemizedlist"><ul type="disc"><li><a href="Assignable.html" title="Concept Assignable">Assignable</a>:
  84. <tt class="computeroutput">variant</tt> is itself <span class="emphasis"><em>Assignable</em></span> if and
  85. only if every one of its bounded types meets the requirements of the
  86. concept. (Note that top-level <tt class="computeroutput">const</tt>-qualified types and
  87. reference types do <span class="emphasis"><em>not</em></span> meet these
  88. requirements.)</li><li><a href="DefaultConstructible.html" title="Concept DefaultConstructible">DefaultConstructible</a> [20.1.4]:
  89. <tt class="computeroutput">variant</tt> is itself
  90. <a href="DefaultConstructible.html" title="Concept DefaultConstructible">DefaultConstructible</a> if and only if its first
  91. bounded type (i.e., <tt class="computeroutput">T1</tt>) meets the requirements of the
  92. concept.</li><li><a href="EqualityComparable.html" title="Concept EqualityComparable">EqualityComparable</a>:
  93. <tt class="computeroutput">variant</tt> is itself <a href="EqualityComparable.html" title="Concept EqualityComparable">EqualityComparable</a>
  94. if and only if every one of its bounded types meets the requirements
  95. of the concept.</li><li><a href="LessThanComparable.html" title="Concept LessThanComparable">LessThanComparable</a>:
  96. <tt class="computeroutput">variant</tt> is itself <a href="LessThanComparable.html" title="Concept LessThanComparable">LessThanComparable</a>
  97. if and only if every one of its bounded types meets the requirements
  98. of the concept.</li><li><a href="variant.reference.html#variant.concepts.output-streamable" title="OutputStreamable"><span class="emphasis"><em>OutputStreamable</em></span></a>:
  99. <tt class="computeroutput">variant</tt> is itself <span class="emphasis"><em>OutputStreamable</em></span>
  100. if and only if every one of its bounded types meets the requirements
  101. of the concept.</li></ul></div></div><div class="section" lang="en"><div class="titlepage"><div><div><h5 class="title"><a name="variant.concepts.static-visitor"></a><span class="emphasis"><em>StaticVisitor</em></span></h5></div></div><div></div></div><div class="toc"><dl><dt><a href="variant.reference.html#variant.concepts.static-visitor.examples">Examples</a></dt></dl></div><p>The requirements on a <span class="bold"><b>static
  102. visitor</b></span> of a type <tt class="computeroutput">T</tt> are as follows:</p><div class="itemizedlist"><ul type="disc"><li>Must allow invocation as a function by overloading
  103. <tt class="computeroutput">operator()</tt>, unambiguously accepting any value of type
  104. <tt class="computeroutput">T</tt>.</li><li>Must expose inner type <tt class="computeroutput">result_type</tt>. (See
  105. <tt class="computeroutput"><a href="id2544445-bb.html" title="Function template visitor_ptr">boost::visitor_ptr</a></tt> for a
  106. solution to using functions as visitors.)</li><li>If <tt class="computeroutput">result_type</tt> is not <tt class="computeroutput">void</tt>, then
  107. each operation of the function object must return a value implicitly
  108. convertible to <tt class="computeroutput">result_type</tt>.</li></ul></div><div class="section" lang="en"><div class="titlepage"><div><div><h6 class="title"><a name="variant.concepts.static-visitor.examples"></a>Examples</h6></div></div><div></div></div><p>The following class satisfies the requirements of a static visitor
  109. of several types (i.e., explicitly: <tt class="computeroutput">int</tt> and
  110. <tt class="computeroutput">std::string</tt>; or, e.g., implicitly: <tt class="computeroutput">short</tt> and
  111. <tt class="computeroutput">const char *</tt>; etc.):</p><pre class="programlisting">class my_visitor
  112. : public <a href="class.boost.static_visitor.html" title="Class template static_visitor">boost::static_visitor</a>&lt;int&gt;
  113. {
  114. public:
  115. int operator()(int i)
  116. {
  117. return i * 2;
  118. }
  119. int operator()(const std::string&amp; s)
  120. {
  121. return s.length();
  122. }
  123. };</pre><p>Another example is the following class, whose function-call
  124. operator is a member template, allowing it to operate on values of many
  125. types. Thus, the following class is a visitor of any type that supports
  126. streaming output (e.g., <tt class="computeroutput">int</tt>, <tt class="computeroutput">double</tt>,
  127. <tt class="computeroutput">std::string</tt>, etc.):</p><pre class="programlisting">class printer
  128. : public <a href="class.boost.static_visitor.html" title="Class template static_visitor">boost::static_visitor</a>&lt;&gt;
  129. {
  130. template &lt;typename T&gt;
  131. void operator()(const T&amp; t)
  132. {
  133. std::cout &lt;&lt; t &lt;&lt; std::endl;
  134. }
  135. };</pre></div></div><div class="section" lang="en"><div class="titlepage"><div><div><h5 class="title"><a name="variant.concepts.output-streamable"></a><span class="emphasis"><em>OutputStreamable</em></span></h5></div></div><div></div></div><p>The requirements on an <span class="bold"><b>output
  136. streamable</b></span> type <tt class="computeroutput">T</tt> are as follows:</p><div class="itemizedlist"><ul type="disc"><li>For any object <tt class="computeroutput">t</tt> of type <tt class="computeroutput">T</tt>,
  137. <tt class="computeroutput">std::cout &lt;&lt; t</tt> must be a valid
  138. expression.</li></ul></div></div></div><div class="section" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="header.boost.variant.hpp"></a>Header &lt;<a href="../../boost/variant.hpp" target="_top">boost/variant.hpp</a>&gt;</h4></div></div><div></div></div><div class="toc"><dl><dt><a href="variant.reference.html#variant.header.include-all"></a></dt></dl></div><div class="section" lang="en"><div class="titlepage"><div></div><div></div></div><p>This header exists simply as a convenience to the user, including
  139. all of the headers in the <tt class="computeroutput">boost/variant</tt> directory.</p></div></div><div class="section" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="header.boost.variant.variant_fwd.hpp"></a>Header &lt;<a href="../../boost/variant/variant_fwd.hpp" target="_top">boost/variant/variant_fwd.hpp</a>&gt;</h4></div></div><div></div></div><div class="toc"><dl></dl></div><p>Provides forward declarations of the
  140. <tt class="computeroutput"><a href="class.boost.variant.html" title="Class template variant">boost::variant</a></tt>,
  141. <tt class="computeroutput"><a href="class.boost.make_variant_over.html" title="Class template make_variant_over">boost::make_variant_over</a></tt>,
  142. <tt class="computeroutput"><a href="class.boost.make_recursive_variant.html" title="Class template make_recursive_variant">boost::make_recursive_variant</a></tt>, and
  143. <tt class="computeroutput"><a href="class.boost.make_recursive_variant_over.html" title="Class template make_recursive_variant_over">boost::make_recursive_variant_over</a></tt>
  144. class templates and the <tt class="computeroutput">boost::recursive_variant_</tt> tag type.
  145. Also defines several preprocessor symbols, as described below.</p><pre class="synopsis">
  146. <a href="BOOST_VARIANT_LIMIT_TYPES.html" title="Macro BOOST_VARIANT_LIMIT_TYPES">BOOST_VARIANT_LIMIT_TYPES</a>
  147. <a href="BOOST_VARIANT_ENUM_PARAMS.html" title="Macro BOOST_VARIANT_ENUM_PARAMS">BOOST_VARIANT_ENUM_PARAMS</a>(param)
  148. <a href="BOOST_VARIANT_ENUM_SHIFTED_PARAMS.html" title="Macro BOOST_VARIANT_ENUM_SHIFTED_PARAMS">BOOST_VARIANT_ENUM_SHIFTED_PARAMS</a>(param)
  149. <a href="BOOST_VARIANT_NO_REFERENCE_SUPPORT.html" title="Macro BOOST_VARIANT_NO_REFERENCE_SUPPORT">BOOST_VARIANT_NO_REFERENCE_SUPPORT</a>
  150. <a href="BOOST_VARIANT_NO_TYPE_SEQUENCE_SUPPORT.html" title="Macro BOOST_VARIANT_NO_TYPE_SEQUENCE_SUPPORT">BOOST_VARIANT_NO_TYPE_SEQUENCE_SUPPORT</a>
  151. <a href="BOOST_VARIANT_NO_FULL_RECURSIVE_VARIANT_SUPPORT.html" title="Macro BOOST_VARIANT_NO_FULL_RECURSIVE_VARIANT_SUPPORT">BOOST_VARIANT_NO_FULL_RECURSIVE_VARIANT_SUPPORT</a></pre></div><div class="section" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="header.boost.variant.variant.hpp"></a>Header &lt;<a href="../../boost/variant/variant.hpp" target="_top">boost/variant/variant.hpp</a>&gt;</h4></div></div><div></div></div><div class="toc"><dl></dl></div><pre class="synopsis"><span class="bold"><b>namespace</b></span> boost {
  152.   <span class="bold"><b>template</b></span>&lt;<span class="bold"><b>typename</b></span> T1, <span class="bold"><b>typename</b></span> T2 = <span class="emphasis"><em>unspecified</em></span>, ...,
  153.            <span class="bold"><b>typename</b></span> TN = <span class="emphasis"><em>unspecified</em></span>&gt;
  154.   <span class="bold"><b>class</b></span> <a href="class.boost.variant.html" title="Class template variant">variant</a>;
  155.   <span class="bold"><b>template</b></span>&lt;<span class="bold"><b>typename</b></span> Sequence&gt; <span class="bold"><b>class</b></span> <a href="class.boost.make_variant_over.html" title="Class template make_variant_over">make_variant_over</a>;
  156.   <span class="bold"><b>template</b></span>&lt;<span class="bold"><b>typename</b></span> T1, <span class="bold"><b>typename</b></span> T2, ..., <span class="bold"><b>typename</b></span> TN&gt;
  157.     <span class="type"><span class="bold"><b>void</b></span></span> <a href="id2518553-bb.html" title="Function template swap">swap</a>(<a href="class.boost.variant.html" title="Class template variant">variant</a>&lt;T1, T2, ..., TN&gt; &amp;, <a href="class.boost.variant.html" title="Class template variant">variant</a>&lt;T1, T2, ..., TN&gt; &amp;);
  158.   <span class="bold"><b>template</b></span>&lt;<span class="bold"><b>typename</b></span> ElemType, <span class="bold"><b>typename</b></span> Traits, <span class="bold"><b>typename</b></span> T1, <span class="bold"><b>typename</b></span> T2, ...,
  159.            <span class="bold"><b>typename</b></span> TN&gt;
  160.     <span class="type">std::basic_ostream&lt;ElemType,Traits&gt; &amp;</span>
  161.     <a href="id2524211-bb.html" title="Function template operator&lt;&lt;"><span class="bold"><b>operator</b></span>&lt;&lt;</a>(std::basic_ostream&lt;ElemType,Traits&gt; &amp;,
  162.                <span class="bold"><b>const</b></span> <a href="class.boost.variant.html" title="Class template variant">variant</a>&lt;T1, T2, ..., TN&gt; &amp;);
  163. }</pre></div><div class="section" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="header.boost.variant.recursive_variant.hpp"></a>Header &lt;<a href="../../boost/variant/recursive_variant.hpp" target="_top">boost/variant/recursive_variant.hpp</a>&gt;</h4></div></div><div></div></div><div class="toc"><dl></dl></div><pre class="synopsis"><span class="bold"><b>namespace</b></span> boost {
  164.   <span class="bold"><b>typedef</b></span> <span class="emphasis"><em>unspecified</em></span> recursive_variant_;
  165.   <span class="bold"><b>template</b></span>&lt;<span class="bold"><b>typename</b></span> T1, <span class="bold"><b>typename</b></span> T2 = <span class="emphasis"><em>unspecified</em></span>, ...,
  166.            <span class="bold"><b>typename</b></span> TN = <span class="emphasis"><em>unspecified</em></span>&gt;
  167.   <span class="bold"><b>class</b></span> <a href="class.boost.make_recursive_variant.html" title="Class template make_recursive_variant">make_recursive_variant</a>;
  168.   <span class="bold"><b>template</b></span>&lt;<span class="bold"><b>typename</b></span> Sequence&gt; <span class="bold"><b>class</b></span> <a href="class.boost.make_recursive_variant_over.html" title="Class template make_recursive_variant_over">make_recursive_variant_over</a>;
  169. }</pre></div><div class="section" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="header.boost.variant.recursive_wrapper.hpp"></a>Header &lt;<a href="../../boost/variant/recursive_wrapper.hpp" target="_top">boost/variant/recursive_wrapper.hpp</a>&gt;</h4></div></div><div></div></div><div class="toc"><dl></dl></div><pre class="synopsis"><span class="bold"><b>namespace</b></span> boost {
  170.   <span class="bold"><b>template</b></span>&lt;<span class="bold"><b>typename</b></span> T&gt; <span class="bold"><b>class</b></span> <a href="class.boost.recursive_wrapper.html" title="Class template recursive_wrapper">recursive_wrapper</a>;
  171.   <span class="bold"><b>template</b></span>&lt;<span class="bold"><b>typename</b></span> T&gt; <span class="bold"><b>class</b></span> <a href="class.boost.is_recursive_wrapper.html" title="Class template is_recursive_wrapper">is_recursive_wrapper</a>;
  172.   <span class="bold"><b>template</b></span>&lt;<span class="bold"><b>typename</b></span> T&gt; <span class="bold"><b>class</b></span> <a href="class.boost.unwrap_recursive_wrapper.html" title="Class template unwrap_recursive_wrapper">unwrap_recursive_wrapper</a>;
  173. }</pre></div><div class="section" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="header.boost.variant.apply_visitor.hpp"></a>Header &lt;<a href="../../boost/variant/apply_visitor.hpp" target="_top">boost/variant/apply_visitor.hpp</a>&gt;</h4></div></div><div></div></div><div class="toc"><dl></dl></div><pre class="synopsis"><span class="bold"><b>namespace</b></span> boost {
  174.   <span class="bold"><b>template</b></span>&lt;<span class="bold"><b>typename</b></span> Visitor&gt; <span class="bold"><b>class</b></span> <a href="class.boost.apply_visitor_delayed_t.html" title="Class template apply_visitor_delayed_t">apply_visitor_delayed_t</a>;
  175.   <span class="bold"><b>template</b></span>&lt;<span class="bold"><b>typename</b></span> Visitor, <span class="bold"><b>typename</b></span> Variant&gt;
  176.     <span class="type"><span class="bold"><b>typename</b></span> Visitor::result_type</span> <a href="id2557051-bb.html" title="Function apply_visitor">apply_visitor</a>(Visitor &amp;, Variant &amp;);
  177.   <span class="bold"><b>template</b></span>&lt;<span class="bold"><b>typename</b></span> Visitor, <span class="bold"><b>typename</b></span> Variant&gt;
  178.     <span class="type"><span class="bold"><b>typename</b></span> Visitor::result_type</span> <a href="id2557051-bb.html" title="Function apply_visitor">apply_visitor</a>(<span class="bold"><b>const</b></span> Visitor &amp;, Variant &amp;);
  179.   <span class="bold"><b>template</b></span>&lt;<span class="bold"><b>typename</b></span> BinaryVisitor, <span class="bold"><b>typename</b></span> Variant1, <span class="bold"><b>typename</b></span> Variant2&gt;
  180.     <span class="type"><span class="bold"><b>typename</b></span> BinaryVisitor::result_type</span>
  181.     <a href="id2557051-bb.html" title="Function apply_visitor">apply_visitor</a>(BinaryVisitor &amp;, Variant1 &amp;, Variant2 &amp;);
  182.   <span class="bold"><b>template</b></span>&lt;<span class="bold"><b>typename</b></span> BinaryVisitor, <span class="bold"><b>typename</b></span> Variant1, <span class="bold"><b>typename</b></span> Variant2&gt;
  183.     <span class="type"><span class="bold"><b>typename</b></span> BinaryVisitor::result_type</span>
  184.     <a href="id2557051-bb.html" title="Function apply_visitor">apply_visitor</a>(<span class="bold"><b>const</b></span> BinaryVisitor &amp;, Variant1 &amp;, Variant2 &amp;);
  185.   <span class="bold"><b>template</b></span>&lt;<span class="bold"><b>typename</b></span> Visitor&gt;
  186.     <span class="type"><a href="class.boost.apply_visitor_delayed_t.html" title="Class template apply_visitor_delayed_t">apply_visitor_delayed_t</a>&lt;Visitor&gt;</span> <a href="id2557051-bb.html" title="Function apply_visitor">apply_visitor</a>(Visitor &amp;);
  187. }</pre></div><div class="section" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="header.boost.variant.get.hpp"></a>Header &lt;<a href="../../boost/variant/get.hpp" target="_top">boost/variant/get.hpp</a>&gt;</h4></div></div><div></div></div><div class="toc"><dl></dl></div><pre class="synopsis"><span class="bold"><b>namespace</b></span> boost {
  188.   <span class="bold"><b>class</b></span> <a href="class.boost.bad_get.html" title="Class bad_get">bad_get</a>;
  189.   <span class="bold"><b>template</b></span>&lt;<span class="bold"><b>typename</b></span> U, <span class="bold"><b>typename</b></span> T1, <span class="bold"><b>typename</b></span> T2, ..., <span class="bold"><b>typename</b></span> TN&gt;
  190.     <span class="type">U *</span> <a href="id2493238-bb.html" title="Function get">get</a>(<a href="class.boost.variant.html" title="Class template variant">variant</a>&lt;T1, T2, ..., TN&gt; *);
  191.   <span class="bold"><b>template</b></span>&lt;<span class="bold"><b>typename</b></span> U, <span class="bold"><b>typename</b></span> T1, <span class="bold"><b>typename</b></span> T2, ..., <span class="bold"><b>typename</b></span> TN&gt;
  192.     <span class="type"><span class="bold"><b>const</b></span> U *</span> <a href="id2493238-bb.html" title="Function get">get</a>(<span class="bold"><b>const</b></span> <a href="class.boost.variant.html" title="Class template variant">variant</a>&lt;T1, T2, ..., TN&gt; *);
  193.   <span class="bold"><b>template</b></span>&lt;<span class="bold"><b>typename</b></span> U, <span class="bold"><b>typename</b></span> T1, <span class="bold"><b>typename</b></span> T2, ..., <span class="bold"><b>typename</b></span> TN&gt;
  194.     <span class="type">U &amp;</span> <a href="id2493238-bb.html" title="Function get">get</a>(<a href="class.boost.variant.html" title="Class template variant">variant</a>&lt;T1, T2, ..., TN&gt; &amp;);
  195.   <span class="bold"><b>template</b></span>&lt;<span class="bold"><b>typename</b></span> U, <span class="bold"><b>typename</b></span> T1, <span class="bold"><b>typename</b></span> T2, ..., <span class="bold"><b>typename</b></span> TN&gt;
  196.     <span class="type"><span class="bold"><b>const</b></span> U &amp;</span> <a href="id2493238-bb.html" title="Function get">get</a>(<span class="bold"><b>const</b></span> <a href="class.boost.variant.html" title="Class template variant">variant</a>&lt;T1, T2, ..., TN&gt; &amp;);
  197. }</pre></div><div class="section" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="header.boost.variant.bad_visit.hpp"></a>Header &lt;<a href="../../boost/variant/bad_visit.hpp" target="_top">boost/variant/bad_visit.hpp</a>&gt;</h4></div></div><div></div></div><div class="toc"><dl></dl></div><pre class="synopsis"><span class="bold"><b>namespace</b></span> boost {
  198.   <span class="bold"><b>class</b></span> <a href="class.boost.bad_visit.html" title="Class bad_visit">bad_visit</a>;
  199. }</pre></div><div class="section" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="header.boost.variant.static_visitor.hpp"></a>Header &lt;<a href="../../boost/variant/static_visitor.hpp" target="_top">boost/variant/static_visitor.hpp</a>&gt;</h4></div></div><div></div></div><div class="toc"><dl></dl></div><pre class="synopsis"><span class="bold"><b>namespace</b></span> boost {
  200.   <span class="bold"><b>template</b></span>&lt;<span class="bold"><b>typename</b></span> ResultType&gt; <span class="bold"><b>class</b></span> <a href="class.boost.static_visitor.html" title="Class template static_visitor">static_visitor</a>;
  201. }</pre></div><div class="section" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="header.boost.variant.visitor_ptr.hpp"></a>Header &lt;<a href="../../boost/variant/visitor_ptr.hpp" target="_top">boost/variant/visitor_ptr.hpp</a>&gt;</h4></div></div><div></div></div><div class="toc"><dl></dl></div><pre class="synopsis"><span class="bold"><b>namespace</b></span> boost {
  202.   <span class="bold"><b>template</b></span>&lt;<span class="bold"><b>typename</b></span> T, <span class="bold"><b>typename</b></span> R&gt; <span class="bold"><b>class</b></span> <a href="class.boost.visitor_ptr_t.html" title="Class template visitor_ptr_t">visitor_ptr_t</a>;
  203.   <span class="bold"><b>template</b></span>&lt;<span class="bold"><b>typename</b></span> R, <span class="bold"><b>typename</b></span> T&gt; <span class="type"><a href="class.boost.visitor_ptr_t.html" title="Class template visitor_ptr_t">visitor_ptr_t</a>&lt;T,R&gt;</span> <a href="id2544445-bb.html" title="Function template visitor_ptr">visitor_ptr</a>(R (*)(T));
  204. }</pre></div></div><table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr><td align="left"><small>Last revised: , at GMT</small></td><td align="right"><small>Copyright © 2002, 2003 Eric Friedman, Itay Maman</small></td></tr></table><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="variant.tutorial.html"><img src="images/prev.png" alt="Prev"></a> </td><td width="20%" align="center"><a accesskey="u" href="variant.html"><img src="images/up.png" alt="Up"></a></td><td width="40%" align="right"> <a accesskey="n" href="BOOST_VARIANT_LIMIT_TYPES.html"><img src="images/next.png" alt="Next"></a></td></tr><tr><td width="40%" align="left" valign="top">Tutorial </td><td width="20%" align="center"><a accesskey="h" href="index.html"><img src="images/home.png" alt="Home"></a></td><td width="40%" align="right" valign="top"> Macro BOOST_VARIANT_LIMIT_TYPES</td></tr></table></div></body></html>
粤ICP备19079148号