Boost logo

Boost :

Subject: Re: [boost] [array] Custom constructr/destructor
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2009-07-18 12:01:52


Kasra wrote:
> I have found an interesting problem regardin using custom allocators/deallocators for an array object.
> Say for example you want to initialise the array to some values and on destruction you want to do something with these values. This at the memoment is not possible. The solution is to create a new class which inherits from array.
> template<class T, std::size_t N>
> class array;
> template<class T, std::size_t N>
> class my_array:
> public array<T,N>
> {
> my_array() { ... }
> ~my_array() { ... }
> };
> Which is not an ideal solution and results in code bloat.

How does it result in code bloat? All the common array code is shared
and only the code specific to your type is separate.

> However a defenition like bellow:
> template<class T, std::size_t N, class PredCtor, class PredDtor>
> class array;
> Means the same code could be used for custom operations during construction and destruction.

array<T, N> must be an aggregate, so it cannot have a constructor
or destructor, even an empty one. How adding specializations to
array better than creating a new class?

> Is there any interest in such a change? If so maybe we could propose this for the standard.

I doubt it.

In Christ,
Steven Watanabe

Boost list run by bdawes at, gregod at, cpdaniel at, john at