boost 1.43 bimap updating question
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 ------------------------------------------------------------------------------
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_tut... 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/referen... -Gabe On Tue, Nov 8, 2011 at 11:57 AM, Damian <dfermin@umich.edu> 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@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (2)
-
Damian
-
Gabriel Redner