function template specialization an implicit casting of arguments

Hi,

I am writing a matrix class. As an auxiliary class, I created classes (class view and const_view) that give access to submatrices into the matrix (cf. iterator ranges, but in two dimensions). As an analogue to the STL algorithms, I can perform actions on these submatrices, e.g.

1
2
template<class const_view, class view>
void add(const_view a, view b);


adds a to b. For float and doubles, I've overloaded this function template with a version that calls the BLAS routines for acceleration. For example:

void add(const_float_view a, float_view b);

A view can be cast implicitly into a const_view. If I call the routine on two non const float_view's, however:

1
2
3
float_view A;
float_view B;
add(A,B);


the compiler does not cast float_view A to float_const_view and does not use the accelerated version. Instead, the original add routine is called with const_view = float_view and view = float_view.

Of course, I can force casting by expliciting it, but this is quite error prone. Is their a way to accelerate the float addition, regardless of the argument's constness?
Last edited on
Topic archived. No new replies allowed.