From: Peter Dimov (pdimov_at_[hidden])
Date: 2001-07-05 09:55:38
From: "George A. Heintzelman" <georgeh_at_[hidden]>
> The second complaint is a little harder to deal with. I often store
> fairly small objects in the any -- ints, floats, doubles, std::strings.
> In these cases, the any is a pointer to an object the size of a
> pointer, and involves unnecessary dynamic memory allocation. I would
> like to see investigated an any implementation where the type is stored
> in the object proper, and 'small' objects are likewise stored in the
> objects. It seems like a no-brainer to store objects up to
> sizeof(pointer) in the object proper (giving the any a
> 2*sizeof(pointer) on most implementations), but where to draw the line
> is probably a question of the specific usage.
It's not exactly a no-brainer because of alignment requirements.
> Finally, I have one suggestion for longer range work. One use of the
> any-type is in returning values from database queries, where the C++
> code doesn't necessarily know what it will get back. In that context,
> one will often get returned arrays of many objects of a single, unknown
> type. It seems silly to store the type of these objects repeatedly.
> Thus, it would be useful to have an any_array type as well, or perhaps
> an any-adapter for STL containers, though some thought needs to go into
> how to do that correctly.
I think that you can return a std::vector<T> wrapped in an 'any'.
-- Peter Dimov Multi Media Ltd.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk