...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
As 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:
Of course, Boost.Any has several advantages over Boost.Variant, such as:
The 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:
Basic |
variant<T&>
|
make_variant_over
|
make_recursive_variant
|
|
---|---|---|---|---|
Borland C++ 5.5.1 and 5.6.4 | X | X | ||
Comeau C++ 4.3.0 | X | X | X | X |
GNU GCC 3.3.1 | X | X | X | X |
GNU GCC 2.95.3 | X | X | X | |
Intel C++ 7.0 | X | X | X | |
Metrowerks CodeWarrior 8.3 | X | X | X | |
Microsoft Visual C++ 7.1 | X | X | X | X |
Microsoft Visual C++ 6 SP5 and 7 | X |
Finally, 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.
Due 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.)
Eric Friedman and Itay Maman designed the initial submission; Eric was the primary implementer.
Eric is also the library maintainer and has expanded upon the initial
submission -- adding
make_recursive_variant
,
make_variant_over
, support for
reference content, etc.
Andrei Alexandrescu's work in [Ale01a] and [Ale02] inspired the library's design.
Jeff Garland was the formal review manager.
Douglas Gregor, Dave Abrahams, Anthony Williams, Fernando Cacciola, Joel de Guzman, Dirk Schreib, Brad King, Giovanni Bajo, Eugene Gladyshev, and others provided helpful feedback and suggestions to refine the semantics, interface, and implementation of the library.