Boost logo

Boost :

From: Joerg Walter (jhr.walter_at_[hidden])
Date: 2002-07-13 14:09:27


----- Original Message -----
From: "George Katsirelos" <gkatsi_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Saturday, July 13, 2002 7:03 PM
Subject: [boost] Bug in ublas?

> 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.

That's definitely a bug.

Please change the erase() functions of map_array in storage_sp.h from

        void erase (pointer it) {
            check (begin () <= it && it < end (), bad_index ());
            *it = value_type (); <--- This is wrong!
        }
        void erase (pointer it1, pointer it2) {
            while (it1 != it2) {
                check (begin () <= it1 && it1 < end (), bad_index ());
                *it1 = value_type (); <--- This is wrong!
                ++ it1;
            }
        }

to

        void erase (pointer it) {
            check (begin () <= it && it < end (), bad_index ());
            (*it).second = data_value_type ();
        }
        void erase (pointer it1, pointer it2) {
            while (it1 != it2) {
                check (begin () <= it1 && it1 < end (), bad_index ());
                (*it1).second = data_value_type ();
                ++ it1;
            }
        }

Thanks for your feedback.

Regards

Joerg

[snip]


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk