
Ublas : 
Subject: [ublas] boundschecking and rounding policies for ublas.vector?
From: Geoff Hilton (geoff.hilton_at_[hidden])
Date: 20090512 21:20:37
Hi, I would like to have the ublas:vector operator+, operator+=,
operator and operator= use a custom boundschecking/rounding policy
class (like one that can be supplied to boost.numeric.interval types
explicitly for example). How would I go about making this happen in the
least convoluted way possible?
...in pseudocode:
namespace ublas = boost::numeric::ublas;
//...
ublas::vector<int
,std::vector<int>
,plus<int>
,minus<int> //not listed here
> vecOne, vecTwo, vecThree;
//fill both with values.
...
vecThree = vecOne + vecTwo;
would call the function written below (ignoring the vector_expression
abstraction) once for each element involved in the vector addition
rather than the default builtin "int ::operator+(int , int)" function:
template<>
int plus<int>::operator ()(const int lhs, const int rhs) const
{
if (boost::integer_traits<int>::const_max  lhs < rhs) {
//rather than cause an error, just return max.
return boost::integer_traits<int>::const_max;
}
return lhs + rhs;
}
Of course the class template interface of vector shown above could be
cleaner with one policy which points to the above plus<int> and a
matching minus<int>, but I didn't want to go into more detail than was
necessary to get my point across.
Thanks,
Geoff