Boost logo

Boost :

From: Martin Bonner (martin.bonner_at_[hidden])
Date: 2006-05-25 10:27:47


----Original Message----
From: boost-bounces_at_[hidden]
[mailto:boost-bounces_at_[hidden]] On Behalf Of Thorsten Ottosen
Sent: 25 May 2006 15:20 To: boost_at_[hidden]
Subject: Re: [boost] [array] optional constructors in Boost.Array

> Martin Bonner wrote:
>> Thorsten Ottosen wrote:
>>
>>> Maybe you should just wrap boost::array:
>>>
>>> template< class T, unsigned N >
>>> struct my_array : boost::array<T,N>
>>> {
>>> // provide constructors here
>>
>>
>> How?
>>
>>
>>> };
>>
>>
>>
>> You can't construct the base boost_array in the base class
>> initialization list of the constructor (because boost_array doesn't
>> have a constructor that takes arguments), and by the time you get
>> into the body of the my_array constructor it is too late - the
>> boost_array is already default constructed.
>
> What do tou mean by "it's too late"?

What I mean is, you can't construct the elements of the boost_array at
that point.
>
> Since the "construction" of boost::array is a no-op, you can just
> initialize it in the body my_array's contructors.

I guess it depends what you want to use my_array for. If you are trying
to hold primitive types, then that wrapping works fine. If you are
trying to hold objects of a class type that doesn't even /have/ a
default constructor, then it just won't work! (and yes, you can put such
objects in a boost_array on a compliant compiler).

-- 
Martin Bonner
Martin.Bonner_at_[hidden]
Pi Technology, Milton Hall, Ely Road, Milton, Cambridge, CB4 6WZ,
ENGLAND Tel: +44 (0)1223 203894

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk