Editing Variant
BOOST WIKI
|
RecentChanges
|
Preferences
|
Page List
|
Links List
A Variant library would provide a class template that acts as a discriminated union. A discriminated union is like a C-style union in that it stores one value whose type may be one of several types listed when building the union. However, a discriminated union tracks which type of value it currently holds, and is therefore type safe (C-style unions are not type safe). A Variant library should provide a variant class template with the following properties: * Interface should support construction and assignment from any of the types that the variant can hold or any type convertible to one of the types that the variant can hold. * Interface should be similar to that of <a href="http://www.boost.org/libs/any/index.html">boost::any</a> for usability reasons. * Support for all types, e.g., types with nontrivial constructors, assignment operators, or destructors. * Stack allocation should be used/allowed so that the variant can be stored efficiently. Stack allocation should be easy using the <a href="http://www.boost.org/libs/type_traits/index.htm#synthesized">type_with_alignment type trait</a> and the <a href="http://www.boost.org/libs/math/doc/common_factor.html#ct_gcd_lcm">compile-time least common denominator routines</a>. The upcoming Metaprogramming Library may help as well. * Recursive types should be allowed, i.e., a variant can hold a value of a type that is constructed using the variant type. Heap allocation is required in such cases. Recursive types were <a href="http://lists.boost.org/MailArchives/boost/msg27504.php">discussed here</a>. * Incomplete types should be allowed. * Provide constructs for performing operations based on the type of the value stored in the variant that can check completeness of decoding. For instance, a 'typeswitch' or visitor construct that is guaranteed to fail at compile time if not all cases are covered. Pattern-matching constructs would be extremely interesting. Syntactical possibilities were <a href="http://aspn.activestate.com/ASPN/Mail/Message/1164988">discussed here</a>. ---- Here are some reference links to Andrei's writings on this subject: *http://cuj.com/experts/2004/alexandr.htm *http://cuj.com/experts/2006/alexandr.htm *http://cuj.com/experts/2008/alexandr.htm and older: *http://www.oonumerics.org/tmpw01/alexandrescu.pdf
Summary:
This change is a minor edit.
(Visit
Preferences
to set your user name.)
View other revisions
BOOST WIKI
|
RecentChanges
|
Preferences
|
Page List
|
Links List
Disclaimer: This site not officially maintained by Boost Developers