Boost logo

Ublas :

From: Paul C. Leopardi (paul.leopardi_at_[hidden])
Date: 2007-05-20 04:19:36


On Fri, 18 May 2007, Gunter Winkler wrote:
> 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

Gunter,
Why is it << ()m rather than << m() ? The syntax seems strange to me.
Thanks, Paul