Boost logo

Boost :

Subject: Re: [boost] base class for boost::array
From: Jeffrey Hellrung (jhellrung_at_[hidden])
Date: 2010-03-15 16:05:02

Peter Myerscough-Jackopson wrote:
> Dear all,
> In using boost::array I have felt the need to pass around boost::array's
> of an unknown size (unknown to the function receiving the array). I have
> therefore created an abstract base class for boost::array so that I can
> create a pointer to a common base class for arrays of different sizes.

Have you read the Boost.Array design rationale?

In any case, I'd imagine an abstract base class for boost::array would
not be well-received. I consider boost::array as basically just an
as-simple-as possible "copy constructible C-array". Anything more
complex is something different than boost::array.

If you want a uniform, size-independent interface for receiving
boost::array parameters, you can use something like the following:

template< class It >
void foo(boost::iterator_range< It > r) { ... }

template< class T, std::size_t N >
void foo(boost::array<T,N>& a) { foo(boost::make_iterator_range(a)); }

See the Boost.Range documentation:

> Since, I think, the ability to allow boost::array to be used in this way
> is that it requires the use of virtual functions, I have written it so
> that the inheritance is optional. It is enabled with a #define before
> including array.hpp .

Using the preprocessor to achieve a policy decision such as this is
probably less preferable compared to using a template parameter.

- Jeff

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