Example:
I have a function that works with vectors:
double interpolate2d(const vector<double> & xvals, const vector<double> & yvals, double xv, double yv, const vector<vector<double> > &fvals) {
int xhi, xlo, yhi, ylo;
double xphi, yphi;
bracketval(xvals,xv,xhi,xlo,xphi);
bracketval(yvals,yv,yhi,ylo,yphi);
return (fvals[xhi][yhi]*xphi+fvals[xlo][yhi]*(1.-xphi))*yphi + (fvals[xhi][ylo]*xphi+fvals[xlo][ylo]*(1.-xphi))*(1.-yphi);
}
But now I want to call it with boost::array elements for the first 2 arguments (same with bracketval()), if std::vector and boost::array were self-implemented, I would be able to derive both from a common base class (interface-like) enforcing an implementation of operator[], since both are library-provided, is there any way to cast/specify such a restriction?
I can always resort to plain c-arrays, but it's not very neat.
Edit: FWIW, here is the original bracketval implementation:
void bracketval(const vector<double> &vals, double v, int &hi, int &lo, double &prophi){
hi=vals.size()-1;
lo=0;
while(abs(hi-lo)>1) {
int md = (hi+lo)/2;
if(vals[md]>v) hi=md; else lo=md;
}
if(vals[hi]!=vals[lo])
prophi = (v-vals[lo])/(vals[hi]-vals[lo]);
else
prophi = 0.5;
}