Boost logo

Boost Users :

Subject: Re: [Boost-users] [multi_index] modify~~
From: joaquin_at_[hidden]
Date: 2010-08-02 07:49:51


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