Boost logo

Ublas :

From: Gunter Winkler (guwi17_at_[hidden])
Date: 2007-05-23 03:07:11


Am Mittwoch, 23. Mai 2007 07:03 schrieb Markus Weimer:
> Hi all,
>
> > However, this is not what I want. I want to be sure that a matrix
> > of double is passed, but that matrix can be of arbitrary type
> > (sparse / dense). How can I achieve that?
>
> I answered my own question and came up with the following definition:
>
> // This code will accept any matrix of type double
> template < template < class DataType > class MatrixType >
> void printDimensions(const matrix_expression< MatrixType <double> > &
> m){ cout << (m()).size1() << "x" << (m()).size2() << endl;
> }

Does this really work? I generally avoid template of template
constructions, because they never worked as I intended.

> Is this the easiest way to achive a matrix-type agnostiv parameter in
> uBLAS?

You can use the boost::enable_if machine combined with the type_traits
library. AFAIR it looks like

template < class MatrixType >
enable_if< is_same< typename MatrixType::value_type, double > >::type
printDimensions(const matrix_expression< MatrixType > & m);

(the enable_if::type is 'void' by default)

mfg
Gunter