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