Boost logo

Boost Users :

Subject: Re: [Boost-users] [multi_index] modify~~
From: isjk (isjk_at_[hidden])
Date: 2010-08-03 02:40:19


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<channel_table, 0>::type ic0,ic1;
boost::tie(ic0, ic1) = get<0>(ct).equal_range(md5_);
channel_table_pr_view ctpv;
while (ic0 != ic1)
{
    ctpv.insert(&*ic0); /// compiled error!
    ++ic0;
}

but it compiled error:
Error 1 error C2664: 'std::pair<_Ty1,_Ty2>
boost::multi_index::detail::ordered_index<KeyFromValue,Compare,SuperMeta,TagList,Category>::insert(channel
*const )' : cannot convert parameter 1 from 'const channel*' to 'channel
*const '.

Joaquin M Lopez Munoz wrote:
>
> 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_at_[hidden]
> 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.

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