Boost logo

Ublas :

From: Gunter Winkler (guwi17_at_[hidden])
Date: 2007-05-18 01:02:22


Am Freitag, 18. Mai 2007 04:15 schrieb Markus Weimer:
> Hi,
>
> I'm a beginner in using ublas and have a few probably obvious
> questions. However, I did not find information on it...
>
> If I were to write a method that should accept any matrix, regardless
> of the storage, which type would I use for that matrix?
>
> Example:
>
> void printDimensions(AnyMatrix m){
> cout << m.size1() << "x" m.size2();
> }
>
> What would be the corresponding base type for vectors?

the simplest way is

template < class M >
void printDimensions(const M& m){
    cout << m.size1() << "x" m.size2();
}

however this method can be called with any type (not only matrices). In
order to have better control of the arguments you should use:

template < class M >
void printDimensions(const ublas::matrix_expression<M>& m){
    cout << ()m.size1() << "x" m().size2();
} // note the extra () !

template < class M >
void printDimensions(const ublas::vector_expression<M>& m){
    cout << ()m.size();
} // note the extra () !

HTH
Gunter