Boost logo

Boost :

From: Jeff Flinn (TriumphSprint2000_at_[hidden])
Date: 2006-08-08 21:29:59


"AlisdairM" <alisdair.meredith_at_[hidden]> wrote in message
news:ebb4tr$6eq$1_at_sea.gmane.org...
> Sylvain Pion wrote:
>
>> I would like to use boost::array as a class data member.
>>
>> This raises a problem when constructing it in the
>> initialization list of the class members:
>>
>> class A {
>> boost::array<int, 3> a;
>> A()
>> : a(???) {} // what do I write here ???
>> };
>>
>> Is there a way to construct the data member efficiently?
>> By efficiently, I mean using copy constructors instead of
>> default constructors followed by assignments of array elements.
>
> This is not possible with the language today.
> Hopefully, there will be changes in the next version of the language
> that make this sort of initialization possible. There are certainly
> several proposals before the committee.
>
> The key problem is that you cannot supply user-declared constructors
> for aggregate classes, and we rely on array being an aggregate for
> brace initialization. Likewise, you can't use brace initialization in
> a constructor initializer list.
>
> I should probaby add a small FAQ to the array docs to describe these
> issues.

Would not the boost.assign library work here?

>> class A {
>> boost::array<int, 3> a;
>> A() : a(boost::assign::list_of(1)(2)(3)(4)) {}
>> };

I don't think I've tried it this way yet.

Jeff Flinn


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