|
Boost Users : |
From: Tom (tom_at_[hidden])
Date: 2003-10-21 23:37:56
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.versus-any
Tom.
"Tom" <tom_at_[hidden]> wrote in message news:bn40gk$emn$1_at_sea.gmane.org...
> 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.
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net