Boost logo

Boost Users :

From: Ferdinand Prantl (prantlf_at_[hidden])
Date: 2008-07-09 10:11:08


On Mon, Jun 30, 2008 at 8:46 PM, Niels Dekker - mail address until
2008-12-31 <nd_mail_address_valid_until_2008-12-31_at_[hidden]> wrote:
> Peter Foelsche wrote:
>>
>> I suggested some time ago to add a special constructor:
>>
>> template<class T, size_t SIZE>
>> any(T _ap[SIZE]);
>>
>> which should do the same like
>> any(T *_p);
>
> Ferdinand Prantl wrote:
>>
>> Well, a little shorter as the static_cast version but still a
>> "superfluous" cast.
>
> I don't know, but it makes sense to me: an array is not just a pointer!
> boost::any always stores a /copy/ of its constructor argument or assignment
> argument. So /if/ it would support built-in arrays, I think it should copy
> their elements internally. Still, it appears technically possible to add
> array support to boost::any, e.g., by having it internally hold a
> wrapper<ValueType>, instead of a ValueType object (as
> holder<ValueType>::held data member):
[snip]
> The wrapper would need to be specialized for array types, copying the array
> elements during construction:

Hi guys,

Thanks for your suggestions! Niels, you nailed it! An array can be used
as a pointer but should not be stored as pointer (generally, at least).

The current requirements of boost::any ensure that the contained object
is always valid there (if not used too wildly). I should have thought
about the copying myself... :-) Your wrapper is an elegant solution
isolating the construction differences from the rest of the holder
template. At first I thought about specializing the holder template
itself but I tend to like you proposal more.

I knocked up the implementation and it seems working well. I will try to
get it to boost.

Thanks again,
Ferda




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