Re: [boost] [array] optional constructors in Boost.Array

----Original Message---- From: boost-bounces@lists.boost.org [mailto:boost-bounces@lists.boost.org] On Behalf Of Thorsten Ottosen Sent: 25 May 2006 15:20 To: boost@lists.boost.org 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@Pitechnology.com Pi Technology, Milton Hall, Ely Road, Milton, Cambridge, CB4 6WZ, ENGLAND Tel: +44 (0)1223 203894

Martin Bonner wrote:
----Original Message---- From: boost-bounces@lists.boost.org [mailto:boost-bounces@lists.boost.org] On Behalf Of Thorsten Ottosen
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).
I see. It's quite hard to see a solution to this without changing array. One might argue that aggregate initialization is less important when we can say array<int,4> = make_array<4>(1)(2)(3)(4); but I guess some people would be against that. -Thorsten

Thorsten Ottosen wrote:
One might argue that aggregate initialization is less important when we can say
array<int,4> = make_array<4>(1)(2)(3)(4);
but I guess some people would be against that.
Aggregate initialization can be static, so in principle the two aren't semantically equivalent.
participants (3)
-
Martin Bonner
-
Peter Dimov
-
Thorsten Ottosen