On Mar 29, 2:19 pm, "mast...@yahoo.com" <mast...@yahoo.com> wrote:
> Boost.Any is one such
>
> > container:http://www.boost.org/doc/html/any.html
>
> I just looked at boost::any and it looks like what I need. Is there
> any restrictions as to why it might not be a good idea to use it ?
> Otherwise it sounds like the way to go isn't it ?
If you have a known set of types (i.e. just
int,float,string,vector,matrix,etc), you may wish to use
boost::variant instead of boost::any. Boost::variant does not perform
any memory allocation (which boost::any must do behind the scenes) and
thus has less overhead. It also has a nice visitor interface which
lets you actually operate on the data without having to check its
type.
However, if you're writing a library, and you just want users to be
able to add and remove any type of data, then boost::any is the way to
go.
Be warned - both any and variant can produce a disheartening amount of
compiler error output if you make a mistake.
-matt