
"AlisdairM" <alisdair.meredith@uk.renaultf1.com> wrote in message news:ebb4tr$6eq$1@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