It appears that there is a new variant library (boost::variant), but that it has been delayed. Also, there is the old boost.any library. And CUJ has a simple, ref-counted one here http://www.cuj.com/documents/s=8034/cuj0010cacciola/cacciola.htm. Also, CUJ has an article about boost::dynamic_any. Which should I use? I want to use one of the boost libraries, but I would like something small - meaning it won't addmuch to the size of my executable. Most boost libraries I can't use because they are too big (due to dependencies I assume). Thanks, Tom.
On Tuesday 21 October 2003 03:09 pm, Tom wrote:
It appears that there is a new variant library (boost::variant), but that it has been delayed. Also, there is the old boost.any library. And CUJ has a simple, ref-counted one here http://www.cuj.com/documents/s=8034/cuj0010cacciola/cacciola.htm. Also, CUJ has an article about boost::dynamic_any.
Which should I use? I want to use one of the boost libraries, but I would like something small - meaning it won't addmuch to the size of my executable. Most boost libraries I can't use because they are too big (due to dependencies I assume).
Well, it depends on your needs. Is the set of types that might go into the variant known at compile time? If so, use boost::variant. If the set of types is not known at compile time, you can use boost::any or dynamic_any (the latter is not yet a Boost library, and is still in development). Doug
"Douglas Gregor"
On Tuesday 21 October 2003 03:09 pm, Tom wrote:
It appears that there is a new variant library (boost::variant), but that it has been delayed. Also, there is the old boost.any library. And CUJ has a simple, ref-counted one here http://www.cuj.com/documents/s=8034/cuj0010cacciola/cacciola.htm. Also, CUJ has an article about boost::dynamic_any.
Which should I use? I want to use one of the boost libraries, but I would like something small - meaning it won't addmuch to the size of my executable. Most boost libraries I can't use because they are too big (due to dependencies I assume).
Well, it depends on your needs. Is the set of types that might go into the variant known at compile time? If so, use boost::variant. If the set of types is not known at compile time, you can use boost::any or dynamic_any (the latter is not yet a Boost library, and is still in development).
Doug
The set of types is known, so I will use variant. But where do I get the latest variant code? It is around, but it isn't listed on the libraries page. The 'beta libraries' link on the libraries page seems to be broken (doesn't take me anywhere). Has the variant library been rejected? Is there a library status page? Thanks, Tom
In partial answer to my own question, I found this description of the difference between boost::any and boost::variant. For me, boost::any will be better because of it's simplicity and because speed is not an issue for me.
Boost.Variant vs. Boost.Any
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:
a.. Boost.Variant guarantees the type of its content is one of a finite, user-specified set of types.
b.. 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.)
c.. 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.)
d.. 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:
a.. Boost.Any, as its name implies, allows virtually any type for its content, providing great flexibility.
b.. Boost.Any provides the no-throw guarantee of exception safety for its swap operation.
c.. Boost.Any makes little use of template metaprogramming techniques (avoiding potentially hard-to-read error messages and significant compile-time processor and memory demands).
I found it here: http://www.cs.rpi.edu/~gregod/boost/doc/html/variant.misc.html#variant.versu...
Tom.
"Tom"
It appears that there is a new variant library (boost::variant), but that it has been delayed. Also, there is the old boost.any library. And CUJ has a simple, ref-counted one here http://www.cuj.com/documents/s=8034/cuj0010cacciola/cacciola.htm. Also, CUJ has an article about boost::dynamic_any.
Which should I use? I want to use one of the boost libraries, but I would like something small - meaning it won't addmuch to the size of my executable. Most boost libraries I can't use because they are too big (due to dependencies I assume).
Thanks, Tom.
participants (2)
-
Douglas Gregor
-
Tom