matrix with custom elements
Irek Szczesniak <[email protected]> Mon, 08 May 2006 13:01:13 -0700
| Newsgroups | gmane.comp.lib.mtl.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi,
I'm trying to create and then print a matrix where the elements are of
some custom type. My sample code is shown at the bottom of my email.
I'm using the newest MTL v. 2.1.2-22 with GCC 3.4.4-2 on Linux 2.6.10.
Unfortunately, when I compile the code I get these errors:
/usr/local/include/mtl/utils.h: In function `void
mtl::print_all_matrix(const Matrix&) [with Matrix = main()::Mat]':
sm.cc:29: instantiated from here
/usr/local/include/mtl/utils.h:178: error: no match for 'operator<<'
in 'std::cout << ((const
mtl::matrix_implementation<mtl::gen_array2D<mtl::dense1D<polynomial,
0> >, mtl::gen_rect_indexer<mtl::row_orien, 0, 0, size_t>
>*)(+A))->mtl::matrix_implementation<TwoDGen, IndexerGen>::operator()
[with TwoDGen = mtl::gen_array2D<mtl::dense1D<polynomial, 0> >,
IndexerGen = mtl::gen_rect_indexer<mtl::row_orien, 0, 0, size_t>](i, j)'
The code compiles if I don't use the print_all_matrix function.
I defined the << operator for the polynomial type, but it didn't help.
It would be great if someone could write me how to fix my problem.
Thanks for reading.
Best,
Irek
************************************************************************
#include <map>
#include <mtl/matrix.h>
using namespace mtl;
using namespace std;
typedef map<int, double> polynomial;
ostream &operator << (ostream &out, const polynomial &p)
{
out << "(";
for(polynomial::const_iterator i = p.begin(); i != p.end(); i++)
out << "(" << i->first << ", " << i->second << ")";
out << ")";
return out;
}
int
main()
{
typedef matrix<polynomial,
rectangle<>,
array< dense<> >,
row_major>::type Mat;
Mat A(10, 10);
print_all_matrix(A);
return 0;
}
_______________________________________________
This list is archived at http://www.osl.iu.edu/MailArchives/mtl-devel/