misc.xml 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!DOCTYPE section PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
  3. "http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
  4. <!--
  5. Copyright 2003, Eric Friedman, Itay Maman.
  6. Distributed under the Boost Software License, Version 1.0. (See accompanying
  7. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  8. -->
  9. <section id="variant.misc">
  10. <title>Miscellaneous Notes</title>
  11. <using-namespace name="boost"/>
  12. <section id="variant.versus-any">
  13. <title>Boost.Variant vs. Boost.Any</title>
  14. <para>As a discriminated union container, the Variant library shares many
  15. of the same features of the <libraryname>Any</libraryname> library.
  16. However, since neither library wholly encapsulates the features of the
  17. other, one library cannot be generally recommended for use over the
  18. other.</para>
  19. <para>That said, Boost.Variant has several advantages over Boost.Any,
  20. such as:
  21. <itemizedlist>
  22. <listitem>Boost.Variant guarantees the type of its content is one of a
  23. finite, user-specified set of types.</listitem>
  24. <listitem>Boost.Variant provides <emphasis>compile-time</emphasis>
  25. checked visitation of its content. (By contrast, the current version
  26. of Boost.Any provides no visitation mechanism at all; but even if it
  27. did, it would need to be checked at run-time.)</listitem>
  28. <listitem>Boost.Variant enables generic visitation of its content.
  29. (Even if Boost.Any did provide a visitation mechanism, it would enable
  30. visitation only of explicitly-specified types.)</listitem>
  31. <listitem>Boost.Variant offers an efficient, stack-based storage scheme
  32. (avoiding the overhead of dynamic allocation).</listitem>
  33. </itemizedlist>
  34. </para>
  35. <para>Of course, Boost.Any has several advantages over Boost.Variant,
  36. such as:
  37. <itemizedlist>
  38. <listitem>Boost.Any, as its name implies, allows virtually any type for
  39. its content, providing great flexibility.</listitem>
  40. <listitem>Boost.Any provides the no-throw guarantee of exception safety
  41. for its swap operation.</listitem>
  42. <listitem>Boost.Any makes little use of template metaprogramming
  43. techniques (avoiding potentially hard-to-read error messages and
  44. significant compile-time processor and memory demands).</listitem>
  45. </itemizedlist>
  46. </para>
  47. </section>
  48. <section>
  49. <title>Portability</title>
  50. <para>The library aims for 100% ANSI/ISO C++ conformance. However, this is
  51. strictly impossible due to the inherently non-portable nature of the
  52. <libraryname>Type Traits</libraryname> library's
  53. <code><classname>type_with_alignment</classname></code> facility. In
  54. practice though, no compilers or platforms have been discovered where this
  55. reliance on undefined behavior has been an issue.</para>
  56. <para>Additionally, significant effort has been expended to ensure proper
  57. functioning despite various compiler bugs and other conformance problems.
  58. To date the library testsuite has
  59. been compiled and tested successfully on at least the following compilers
  60. for basic and advanced functionality:
  61. <informaltable>
  62. <tgroup cols="5">
  63. <thead>
  64. <row>
  65. <entry></entry>
  66. <entry>Basic</entry>
  67. <entry>
  68. <code>variant&lt;T&amp;&gt;</code>
  69. </entry>
  70. <entry>
  71. <link linkend="variant.tutorial.over-sequence">
  72. <code>make_variant_over</code>
  73. </link>
  74. </entry>
  75. <entry>
  76. <link linkend="variant.tutorial.recursive.recursive-variant">
  77. <code>make_recursive_variant</code>
  78. </link>
  79. </entry>
  80. </row>
  81. </thead>
  82. <tbody>
  83. <row>
  84. <entry>Borland C++ 5.5.1 and 5.6.4</entry>
  85. <entry>X</entry>
  86. <entry>X</entry>
  87. <entry></entry>
  88. <entry></entry>
  89. </row>
  90. <row>
  91. <entry>Comeau C++ 4.3.0</entry>
  92. <entry>X</entry>
  93. <entry>X</entry>
  94. <entry>X</entry>
  95. <entry>X</entry>
  96. </row>
  97. <row>
  98. <entry>GNU GCC 3.3.1</entry>
  99. <entry>X</entry>
  100. <entry>X</entry>
  101. <entry>X</entry>
  102. <entry>X</entry>
  103. </row>
  104. <row>
  105. <entry>GNU GCC 2.95.3</entry>
  106. <entry>X</entry>
  107. <entry>X</entry>
  108. <entry></entry>
  109. <entry>X</entry>
  110. </row>
  111. <row>
  112. <entry>Intel C++ 7.0</entry>
  113. <entry>X</entry>
  114. <entry></entry>
  115. <entry>X</entry>
  116. <entry>X</entry>
  117. </row>
  118. <row>
  119. <entry>Metrowerks CodeWarrior 8.3</entry>
  120. <entry>X</entry>
  121. <entry></entry>
  122. <entry>X</entry>
  123. <entry>X</entry>
  124. </row>
  125. <row>
  126. <entry>Microsoft Visual C++ 7.1</entry>
  127. <entry>X</entry>
  128. <entry>X</entry>
  129. <entry>X</entry>
  130. <entry>X</entry>
  131. </row>
  132. <row>
  133. <entry>Microsoft Visual C++ 6 SP5 and 7</entry>
  134. <entry>X</entry>
  135. <entry></entry>
  136. <entry></entry>
  137. <entry></entry>
  138. </row>
  139. </tbody>
  140. </tgroup>
  141. </informaltable>
  142. </para>
  143. <para>Finally, the current state of the testsuite in CVS may be found on the
  144. <ulink url="http://boost.sourceforge.net/regression-logs">Test Summary</ulink>
  145. page. Please note, however, that this page reports on day-to-day changes
  146. to inter-release code found in the Boost CVS and thus likely does not
  147. match the state of code found in Boost releases.</para>
  148. </section>
  149. <section id="variant.troubleshooting">
  150. <title>Troubleshooting</title>
  151. <para>Due to the heavy use of templates in the implementation of
  152. <code>variant</code>, it is not uncommon when compiling to encounter
  153. problems related to template instantiaton depth, compiler memory, etc. This
  154. section attempts to provide advice to common problems experienced on several
  155. popular compilers.</para>
  156. <para>(This section is still in progress, with additional advice/feedback
  157. welcome. Please post to the Boost-Users list with any useful experiences you
  158. may have.)</para>
  159. <section id="variant.troubleshooting.template-depth">
  160. <title>&quot;Template instantiation depth exceeds maximum&quot;</title>
  161. <section id="variant.troubleshooting.template-depth.gcc">
  162. <title>GNU GCC</title>
  163. <para>The compiler option
  164. <code>-ftemplate-depth-<emphasis>NN</emphasis></code> can increase the
  165. maximum allowed instantiation depth. (Try
  166. <code>-ftemplate-depth-50</code>.)</para>
  167. </section>
  168. </section>
  169. <section id="variant.troubleshooting.compiler-memory">
  170. <title>&quot;Internal heap limit reached&quot;</title>
  171. <section id="variant.troubleshooting.compiler-memory.msvc">
  172. <title>Microsoft Visual C++</title>
  173. <para>The compiler option <code>/Zm<emphasis>NNN</emphasis></code> can
  174. increase the memory allocation limit. The <code>NNN</code> is a
  175. scaling percentage (i.e., <code>100</code> denotes the default limit).
  176. (Try <code>/Zm200</code>.)</para>
  177. </section>
  178. </section>
  179. </section>
  180. <section id="variant.ack">
  181. <title>Acknowledgments</title>
  182. <para>Eric Friedman and Itay Maman designed the initial submission; Eric was
  183. the primary implementer.</para>
  184. <para>Eric is also the library maintainer and has expanded upon the initial
  185. submission -- adding
  186. <code><classname>make_recursive_variant</classname></code>,
  187. <code><classname>make_variant_over</classname></code>, support for
  188. reference content, etc.</para>
  189. <para>Andrei Alexandrescu's work in
  190. [<link linkend="variant.refs.ale01a">Ale01a</link>]
  191. and
  192. [<link linkend="variant.refs.ale02">Ale02</link>]
  193. inspired the library's design.</para>
  194. <para>Jeff Garland was the formal review manager.</para>
  195. <para>Douglas Gregor,
  196. Dave Abrahams,
  197. Anthony Williams,
  198. Fernando Cacciola,
  199. Joel de Guzman,
  200. Dirk Schreib,
  201. Brad King,
  202. Giovanni Bajo,
  203. Eugene Gladyshev,
  204. and others provided helpful feedback and suggestions to refine the semantics,
  205. interface, and implementation of the library.</para>
  206. </section>
  207. </section>