Miscellaneous NotesBoost.Variant vs. Boost.AnyAs a discriminated union container, the Variant library shares many
of the same features of the Any library.
However, since neither library wholly encapsulates the features of the
other, one library cannot be generally recommended for use over the
other.That said, Boost.Variant has several advantages over Boost.Any,
such as:
Boost.Variant guarantees the type of its content is one of a
finite, user-specified set of types.Boost.Variant provides compile-time
type-safe visitation of its content. (By contrast, the current version
of Boost.Any provides no visitation mechanism at all.)Boost.Variant enables generic visitation of its content.
(Even if Boost.Any did provide a visitation mechanism, it would enable
visitation only of explicitly-specified types.)Boost.Variant offers an efficient, stack-based storage scheme
(avoiding the overhead of dynamic allocation).Of course, Boost.Any has several advantages over Boost.Variant,
such as:
Boost.Any, as its name implies, allows virtually any type for
its content, providing great flexibility.Boost.Any provides the no-throw guarantee of exception safety
for its swap operation.Boost.Any makes little use of template metaprogramming
techniques (avoiding potentially hard-to-read error messages and
significant compile-time processor and memory demands).PortabilityThe library aims for 100% ANSI/ISO C++ conformance. However, this is
strictly impossible due to the inherently non-portable nature of the
Type Traits library's
type_with_alignment facility. In
practice though, no compilers or platforms have been discovered where this
reliance on undefined behavior has been an issue.Additionally, significant effort has been expended to ensure proper
functioning despite various compiler bugs and other conformance problems.
To date the library testsuite has
been compiled and tested successfully on at least the following compilers
for basic and advanced functionality:
Basicvariant<T&>variant<types>recursive_variantBorland C++ 5.5.1 and 5.6.4XComeau C++ 4.3.0XXXXGNU GCC 3.3.1XXXXGNU GCC 2.95.3XXXIntel C++ 7.0XXXXMetrowerks CodeWarrior 8.3XXXXMicrosoft Visual C++ 7.1XXXXMicrosoft Visual C++ 6 SP5 and 7XFinally, the current state of the testsuite in CVS may be found on the
Test Summary
page. Please note, however, that this page reports on day-to-day changes
to inter-release code found in the Boost CVS and thus likely does not
match the state of code found in Boost releases.TroubleshootingDue to the heavy use of templates in the implementation of
variant, it is not uncommon when compiling to encounter
problems related to template instantiaton depth, compiler memory, etc. This
section attempts to provide advice to common problems experienced on several
popular compilers.(This section is still in progress, with additional advice/feedback
welcome. Please post to the Boost-Users list with any useful experiences you
may have.)"Template instantiation depth exceeds maximum"GNU GCCThe compiler option
-ftemplate-depth-NN can increase the
maximum allowed instantiation depth. (Try
-ftemplate-depth-50.)"Internal heap limit reached"Microsoft Visual C++The compiler option /ZmNNN can
increase the memory allocation limit. The NNN is a
scaling percentage (i.e., 100 denotes the default limit).
(Try /Zm200.)