
hi, now, I have two structures like this, struct peer { int guid_; }; struct channel { int md5_; peer* pr_; int prop_; }; ------------------------------------------ peer and channel is many to many. using example6::key_from_key class; ------------------------------------------ typedef multi_index_container< peer, index_by< ordered_unique< BOOST_MULTI_INDEX_MEMBER(peer, int, guid_) >
peer_table;
typedef multi_index_container< channel, index_by< ordered_non_unique< BOOST_MULTI_INDEX_MEMBER(channel, int, md5_) >
channel_table;
typedef multi_index_container< const channel*, ordered_non_unique< key_from_key< BOOST_MULTI_INDEX_MEMBER(peer, const int, guid_), BOOST_MULTI_INDEX_MEMBER(channel, const peer*, pr_) > >
channel_table_pr_view;
peer_table pt;
channel_table ct;
/// insert very much data....
nth_index

isjk escribió:
hi,
now, I have two structures like this,
[...]
typedef multi_index_container< const channel*, ordered_non_unique< key_from_key< BOOST_MULTI_INDEX_MEMBER(peer, const int, guid_), BOOST_MULTI_INDEX_MEMBER(channel, const peer*, pr_) > >
channel_table_pr_view;
[...]
channel_table_pr_view::iterator ictpv = ctpv.find(guid_); if (ictpv != ctpv.end()) { ctpv.modify(ictpv, _Modify_prop()); // right or not? }
struct _Modify_prop{ void operator()(channel& cl_) { cl_.prop = rand(); } };
This is not correct: _Modify_prop is passed a reference to the element of channel_table_pr_view, which is a const channel*, so the right signature for _Modify_prop::operator() is struct _Modify_prop{ void operator()(const channel*& pcl_); }; Due to the const qualifier you won't be able to do the modification, so consider redefining channel_table_pr_view as holding pointers to non-const objects: typedef multi_index_container< channel*, ordered_non_unique< ...
channel_table_pr_view;
and making the necessary adjustments. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

it compiled error! I redefined "channel_table_pr_view" like this, typedef multi_index_container< channel*, ordered_non_unique< key_from_key< BOOST_MULTI_INDEX_MEMBER(peer, int guid_), BOOST_MULTI_INDEX_MEMBER(channel, peer* pr_) >
channel_table_pr_view; and insert some element like this,
peer_table pt_;
const peer* pr1_ = *&(pt_.insert(peer(1)).first);
const peer* pr2_ = *&(pt_.insert(peer(2)).first);
... other 1000000
channel_table ct_;
ct.insert(channel(1, pr1_, 0));
ct.insert(channel(2, pr2_, 2));
ct.insert(channel(3, pr3_, 4));
... other 100000
nth_index
isjk escribió:
hi,
now, I have two structures like this,
[...]
typedef multi_index_container< const channel*, ordered_non_unique< key_from_key< BOOST_MULTI_INDEX_MEMBER(peer, const int, guid_), BOOST_MULTI_INDEX_MEMBER(channel, const peer*, pr_) > >
channel_table_pr_view;
[...]
channel_table_pr_view::iterator ictpv = ctpv.find(guid_); if (ictpv != ctpv.end()) { ctpv.modify(ictpv, _Modify_prop()); // right or not? }
struct _Modify_prop{ void operator()(channel& cl_) { cl_.prop = rand(); } };
This is not correct: _Modify_prop is passed a reference to the element of channel_table_pr_view, which is a const channel*, so the right signature for _Modify_prop::operator() is
struct _Modify_prop{ void operator()(const channel*& pcl_); };
Due to the const qualifier you won't be able to do the modification, so consider redefining channel_table_pr_view as holding pointers to non-const objects:
typedef multi_index_container< channel*, ordered_non_unique< ...
channel_table_pr_view;
and making the necessary adjustments.
Joaquín M López Muñoz Telefónica, Investigación y Desarrollo _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- View this message in context: http://old.nabble.com/-multi_index--modify%7E%7E-tp29322711p29332372.html Sent from the Boost - Users mailing list archive at Nabble.com.

isjk escribió:
it compiled error! [...]
Please don't top-post and try to follow the discussion policies of the list as summarized at http://www.boost.org/community/policy.html Would you care to reply again (to my post from yesterday, not to this one) observing these policies so that users of the list can comfortably follow the discussion? Thank you! Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
participants (2)
-
isjk
-
joaquin@tid.es