Boost logo

Boost Users :

Subject: Re: [Boost-users] boost 1.43 bimap updating question
From: Gabriel Redner (gredner_at_[hidden])
Date: 2011-11-09 10:10:05


Hi Damian,

In general you cannot update bimap entries via iterators:
http://www.boost.org/doc/libs/1_43_0/libs/bimap/doc/html/boost_bimap/the_tutorial/differences_with_standard_maps.html#boost_bimap.the_tutorial.differences_with_standard_maps.iterator__value_type

You can do so via the 'replace_data' member function:
http://www.boost.org/doc/libs/1_43_0/libs/bimap/doc/html/boost_bimap/reference/set_of_reference.html#reference_set_of_replace_data_iterator_data

-Gabe

On Tue, Nov 8, 2011 at 11:57 AM, Damian <dfermin_at_[hidden]> wrote:
> Hello.
>
> I'm trying to update the data of a left bimap and I keep getting this error
> message:
> error: assignment of read-only data-member
> ‘boost::bimaps::relation::detail::normal_storage<boost::bimaps::tags::tagged<const
> int, boost::bimaps::relation::member_at::left>,
> boost::bimaps::tags::tagged<const double,
> boost::bimaps::relation::member_at::right> >::second’
>
>
> Here is what I'm doing:
>
> int idx = 0;
> double score = 0.0;
>
> typedef boost::bimap<int, double> bm_type; // define the bimap type we will
> use
> bm_type bm;
> bm_type::right_iterator r_iter;
> bm_type::left_iterator l_iter;
>
> bm.insert( bm_type::value_type( 1, 93.9) );
> bm.insert( bm_type::value_type( 2, 18.3) );
> bm.insert( bm_type::value_type( 3, 4.54) );
> bm.insert( bm_type::value_type( 4, 0.343) );
>
> score = 60000.0343;
> idx = 3;
>
> l_iter = bm.left.find(idx);
> if(l_iter == bm.left.end()) { // this is a new entry so add it
> bm.insert( bm_type::value_type( idx, score) );
> }
> else { // we have this idx value in the bimap
>
> // update the bimap score value only if the current value
> // of score is greater than what is currently in the bimap
> // for the same index (idx) value.
> if( l_iter->second < score ) {
> l_iter->second = score;
> }
> }
>
>
> Can someone tell me what I'm doing wrong?
> The double value in the map is the only part that needs to be updated and
> only if a new (higher) score is observed.
>
> Thanks,
> Damian
>
>
> --
> ------------------------------------------------------------------------------
> Damian Fermin, Ph.D.
> Pathology Department
> University of Michigan
> 4237 Medical Science I
> 1301 Catherine
> Ann Arbor, MI 48109-0602
> 734.615.0302
>
> "There is No Gene for the Human Spirit"
>        -- GATTACA
> ------------------------------------------------------------------------------
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net