Boost logo

Boost :

Subject: [boost] base class for boost::array
From: Peter Myerscough-Jackopson (peter.myerscough-jackopson_at_[hidden])
Date: 2010-03-15 12:30:52


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.
Essentially std::vector's of different sizes can be passed into a
function with a fixed prototype, but because boost::array constructs a
different type for each array size, a single fixed prototype cannot be
described such that it can be called with different sizes of
boost::array.

 

In code I can write (toy functions) :

 

double sumTotal(const std::vector<double>* values)

{

   double result = 0 ;

   BOOST_FOREACH(double v, values)

   {

      result += v;

   }

   return result;

}

 

But I can't write:

 

double sumTotal(const boost::array<double>* values)

{

   double result = 0 ;

   BOOST_FOREACH(double v, values)

   {

      result += v;

   }

   return result;

}

 

Without the second function being a template function, i.e. I cannot
provide a library that takes a boost::array<double>. With the attached
base class, I could define a function that takes a
boost::array_base<double>.

 

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 .

 

Is this useful? (I am aware that I maybe could use a boost::range)

 

Thanks for your time,

 

Peter

 

Ps. On my current compiler, swap and operator= could not be uncommented
in the array_base class.

PPs. This is my first post to boost dev, please be kind... J

 

Dr Peter Myerscough-Jackopson - Senior Engineer

Tel: +44 (0)23 8076 7808 Fax: +44 (0)23 8076 0602
Web: http://www.macltd.com/ <BLOCKED::http://www.macltd.com/> Email:
peter.myerscough-jackopson_at_[hidden]
<mailto:peter.myerscough-jackopson_at_[hidden]>
MULTIPLE ACCESS COMMUNICATIONS LIMITED is a company registered in
England at Delta House, The University of Southampton Science Park,
Southampton, SO16 7NS, United Kingdom with Company Number 1979185 and
VAT Number GB 411942866

 





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