From: Michael Tegtmeyer (tegtmeye_at_[hidden])
Date: 2006-01-24 16:43:08


Hello,

I am trying to guage interest in a fixed sized version of valarray. I
frequently found myself using small(-ish) compile-time known sized
numeric arrays that don't justify the overhead of operator new in
std::valarray but needed the math interface that valarray provided. I
wrote a static-sized version of valarray for this purpose. It is modeled
after std::valarray and implements about 90% of valarray's interface
(obviously resizing is not included, neither is gslice due to the result
not being known at compile time). Examples of it's use are:

float _v[10] = {...};
size_t _i[5] = {...};

cvalarray<float,10> v1(_v);
cvalarray<float,5> v2 = v1[cslice<0,5,2>()];
v1[cslice<0,3,3>()] = 0.0f;

cvalarray<size_t,5> ind(_i);
cvalarray<float,5> cvalB = v1[ind];

v2 *= (v2 + v1) / 2.0;
//all of the usual math ops

I have a complete implementation that models std::valarray in every
possible way (with compile-time known limitations) including
expression-template support for the numeric ops. My testing indicates a
decent performance increase over gcc4's valarray for small number of
elements <1000.

If anyone has any interest, I'll put together some docs and throw it in
the sandbox.

Mike Tegtmeyer