MTL 4: Frequently Asked Questions
The problem is that certain objects cannot be accessed during insertion, in particular sparse and distributed matrices.
The following program fragment is wrong:
using namespace mtl; typedef compressed2D<double> matrix_type; matrix_type A(5, 5); matrix::inserter<matrix_type> ins(A); ins[0][0] << 7.3; // .... more insertions do_something_with(A); // TROUBLE!!!
The insertion is only finished when the inserter is destroyed. This can be achieved in two ways:
An extra scope is implicitly used when the insertion is performed in a separate function, as done here.
The easiest way to destroy the inserter is to enclose the insertion in braces:
using namespace mtl; typedef compressed2D<double> matrix_type; matrix_type A(5, 5); { matrix::inserter<matrix_type> ins(A); ins[0][0] << 7.3; } // ins is destroyed here do_something_with(A); // and A is ready to use
The trouble comes from the fact that there are namespaces traits in mtl as well as in mtl::matrix. Within namespace mtl::matrix, the name traits::xyz is searched in mtl::matrix::traits not in mtl::traits.
The quick solution is to replace traits::xyz by mtl::traits::xyz to nominate the namespace explicitly.
The best solution is to send us (mtl4@osl.iu.edu) a bug report and we will fix it for everybody.
Frequently Asked Questions -- MTL 4 -- Peter Gottschling and Andrew Lumsdaine
-- Gen. with
rev. 7542
on 7 Apr 2011 by doxygen 1.5.9 -- © 2010 by SimuNova UG.