Boost logo

Ublas :

From: Thomas Lemaire (thomas.lemaire_at_[hidden])
Date: 2005-10-07 02:46:36


On Friday 07 October 2005 01:02, Paul C. Leopardi wrote:
> Could you please elaborate? If your method is virtual, why can it not be
> template? In what way is it different from the virtual template member
> functions which are used in the template class glucat::clifford_algebra in
> GluCat, for example? See http://sourceforge.net/projects/glucat/
> These functions are inherited at compile time by the template classes
> glucat::matrix_multi and glucat::framed_multi, using a variant of the
> Barton-Nackman trick, otherwise known as Curiously Recurring Templates.

My method cannot be template because the compiler complains about it. It is a
matter of virtual table which would be undefined (I am not 100% sure of what
I am saying...). In your case, the whole class is template.

> This part of the Wiki talks about runtime polymorphism. The template class
> glucat::clifford_algebra uses compile time polymorphism. Do you need
> runtime polymorphism or could you do what you want using only compile time
> polymorphism?

Yes, I need need runtime polymorphism, that's the point...

I would like to achieve something like this:

class Foo {
/* ... */

template<class Vec1, class Vec2>
virtual void doSomeThing(Vec1 const& v1, Vec2 & v2);

// and also with virtual pure method

/* ... */
};

Actually I am only using vector<double> and vector_range< vector<double> >, so
I could manage things using intermediate functions and project/subrange like
this:

class Foo {
/* ... */

void doSomeThing(vec const& v1, vec & v2) {
    doSomething(subrange(v1,0,v1.size()), subrange(v2,0,v2.size()));
};

void doSomeThing(vec_range const& v1, vec & v2) {
    doSomething(v1, subrange(v2,0,v2.size()));
};

void doSomeThing(vec const& v1, vec_range & v2) {
    doSomething(subrange(v1,0,v1.size()), v2);
};

virtual void doSomeThing(vec_range const& v1, vec_range & v2);

/* ... */
};

Sometimes I have 3 vector-arguments for doSomeThing(), it is really a pain,,,
And I also sometime use fixed size vector !!

cheers,

-- 
thomas