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">
5 Copyright 2003, Eric Friedman, Itay Maman.
7 Distributed under the Boost Software License, Version 1.0. (See accompanying
8 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
10 <section id=
"variant.misc">
11 <title>Miscellaneous Notes
</title>
13 <using-namespace name=
"boost"/>
15 <section id=
"variant.versus-any">
16 <title>Boost.Variant vs. Boost.Any
</title>
18 <para>As a discriminated union container, the Variant library shares many
19 of the same features of the
<libraryname>Any
</libraryname> library.
20 However, since neither library wholly encapsulates the features of the
21 other, one library cannot be generally recommended for use over the
24 <para>That said, Boost.Variant has several advantages over Boost.Any,
28 <listitem>Boost.Variant guarantees the type of its content is one of a
29 finite, user-specified set of types.
</listitem>
30 <listitem>Boost.Variant provides
<emphasis>compile-time
</emphasis>
31 checked visitation of its content. (By contrast, the current version
32 of Boost.Any provides no visitation mechanism at all; but even if it
33 did, it would need to be checked at run-time.)
</listitem>
34 <listitem>Boost.Variant enables generic visitation of its content.
35 (Even if Boost.Any did provide a visitation mechanism, it would enable
36 visitation only of explicitly-specified types.)
</listitem>
37 <listitem>Boost.Variant offers an efficient, stack-based storage scheme
38 (avoiding the overhead of dynamic allocation).
</listitem>
43 <para>Of course, Boost.Any has several advantages over Boost.Variant,
47 <listitem>Boost.Any, as its name implies, allows virtually any type for
48 its content, providing great flexibility.
</listitem>
49 <listitem>Boost.Any provides the no-throw guarantee of exception safety
50 for its swap operation.
</listitem>
51 <listitem>Boost.Any makes little use of template metaprogramming
52 techniques (avoiding potentially hard-to-read error messages and
53 significant compile-time processor and memory demands).
</listitem>
61 <title>Portability
</title>
63 <para>The library aims for
100% ANSI/ISO C++ conformance. However, this is
64 strictly impossible due to the inherently non-portable nature of the
65 <libraryname>Type Traits
</libraryname> library's
66 <code><classname>type_with_alignment
</classname></code> facility. In
67 practice though, no compilers or platforms have been discovered where this
68 reliance on undefined behavior has been an issue.
</para>
70 <para>Additionally, significant effort has been expended to ensure proper
71 functioning despite various compiler bugs and other conformance problems.
72 To date the library testsuite has
73 been compiled and tested successfully on at least the following compilers
74 for basic and advanced functionality:
83 <code>variant
<T
&></code>
86 <link linkend=
"variant.tutorial.over-sequence">
87 <code>make_variant_over
</code>
91 <link linkend=
"variant.tutorial.recursive.recursive-variant">
92 <code>make_recursive_variant
</code>
99 <entry>Borland C++
5.5.1 and
5.6.4</entry>
106 <entry>Comeau C++
4.3.0</entry>
113 <entry>GNU GCC
3.3.1</entry>
120 <entry>GNU GCC
2.95.3</entry>
127 <entry>Intel C++
7.0</entry>
134 <entry>Metrowerks CodeWarrior
8.3</entry>
141 <entry>Microsoft Visual C++
7.1</entry>
148 <entry>Microsoft Visual C++
6 SP5 and
7</entry>
160 <para>Finally, the current state of the testsuite in CVS may be found on the
161 <ulink url=
"http://boost.sourceforge.net/regression-logs">Test Summary
</ulink>
162 page. Please note, however, that this page reports on day-to-day changes
163 to inter-release code found in the Boost CVS and thus likely does not
164 match the state of code found in Boost releases.
</para>
168 <section id=
"variant.troubleshooting">
169 <title>Troubleshooting
</title>
171 <para>Due to the heavy use of templates in the implementation of
172 <code>variant
</code>, it is not uncommon when compiling to encounter
173 problems related to template instantiaton depth, compiler memory, etc. This
174 section attempts to provide advice to common problems experienced on several
175 popular compilers.
</para>
177 <para>(This section is still in progress, with additional advice/feedback
178 welcome. Please post to the Boost-Users list with any useful experiences you
181 <section id=
"variant.troubleshooting.template-depth">
182 <title>"Template instantiation depth exceeds maximum
"</title>
184 <section id=
"variant.troubleshooting.template-depth.gcc">
185 <title>GNU GCC
</title>
186 <para>The compiler option
187 <code>-ftemplate-depth-
<emphasis>NN
</emphasis></code> can increase the
188 maximum allowed instantiation depth. (Try
189 <code>-ftemplate-depth-
50</code>.)
</para>
193 <section id=
"variant.troubleshooting.compiler-memory">
194 <title>"Internal heap limit reached
"</title>
196 <section id=
"variant.troubleshooting.compiler-memory.msvc">
197 <title>Microsoft Visual C++
</title>
198 <para>The compiler option
<code>/Zm
<emphasis>NNN
</emphasis></code> can
199 increase the memory allocation limit. The
<code>NNN
</code> is a
200 scaling percentage (i.e.,
<code>100</code> denotes the default limit).
201 (Try
<code>/Zm200
</code>.)
</para>
207 <section id=
"variant.ack">
208 <title>Acknowledgments
</title>
210 <para>Eric Friedman and Itay Maman designed the initial submission; Eric was
211 the primary implementer.
</para>
213 <para>Eric is also the library maintainer and has expanded upon the initial
215 <code><classname>make_recursive_variant
</classname></code>,
216 <code><classname>make_variant_over
</classname></code>, support for
217 reference content, etc.
</para>
219 <para>Andrei Alexandrescu's work in
220 [
<link linkend=
"variant.refs.ale01a">Ale01a
</link>]
222 [
<link linkend=
"variant.refs.ale02">Ale02
</link>]
223 inspired the library's design.
</para>
225 <para>Jeff Garland was the formal review manager.
</para>
227 <para>Douglas Gregor,
236 and others provided helpful feedback and suggestions to refine the semantics,
237 interface, and implementation of the library.
</para>