|
Boost : |
From: George Katsirelos (gkatsi_at_[hidden])
Date: 2002-07-13 12:03:22
Hi,
The piece of code at the end of this mail produces unexpected output.
Briefly, calling erase() on a sparse vector does weird things to the
contents of that vector, even though the iterators still work (somewhat)
correctly.
Note that after the call to d.erase(5), elements 2 and 3 do not appear
in the output, even though they are there when iterating. Also note the
0 == 0 that appears.
The compiler is gcc 3.1.
This seems like a bug or, if not, very counterintuitive behavior.
Thanks,
George
int main()
{
using namespace boost::numerics;
sparse_vector<double> d(10);
d[2] = 3.;
d[3] = 5.;
d[7] = 10.;
if(d[5] > 3.0 )
std::cout << "will not be printed\n";
std::cout << d << '\n';
d.erase(5);
std::cout << d << '\n';
for( sparse_vector<double>::iterator i = d.begin(); i != d.end(); ++i ) {
std::cout << i.index() << " == " << *i << '\n';
}
sparse_vector<double> d1(d);
std::cout << d1 << '\n';
for( sparse_vector<double>::iterator i = d1.begin(); i != d1.end();
++i ) {
std::cout << i.index() << " == " << *i << '\n';
}
return 0;
}
The output is:
[10](0,0,3,5,0,0,0,10,0,0)
[10](0,0,0,0,0,0,0,10,0,0)
2 == 3
3 == 5
0 == 0
7 == 10
[10](0,0,0,0,0,0,0,10,0,0)
2 == 3
3 == 5
0 == 0
7 == 10
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk