Boost logo

Boost Users :

Subject: Re: [Boost-users] [multi_index_container] Using modify_key vs modify
From: Joaquin M LópezMuñoz (joaquin_at_[hidden])
Date: 2015-09-28 01:57:47


Muruganand Karthikeyan <muruthegun <at> gmail.com> writes:

> Hello!
>
> Under what circumstances should we use modify_key? I believe we can
> achieve the same result using modify, so what is the advantage in
> using modify_key?

modify_key is provided as a convenience when the part of the element
you want to change is precisely its key. Otherwise modify is perfectly
fine here too, the only difference is that the modifying functor is
passed a reference to the whole element. For example, the following

  struct X
  {
    int n,m;
  };

  using multi_t=multi_index_container<
    X,
    indexed_by<
      ordered_non_unique<member<X,int,&X::n>>
>
>;
  ...
  multi_t m=...;
  auto it=m.find(5);
  m.modify(it,[](X& x){x.n=8;});
  
is entirely equivalent t(€€¸¸¸(€…ÕѼ¥Ðõ´¹™¥¹ Ô¤ì(€´¹µ½‘¥™å}­•ä¡¥Ð±mt¡¥¹Ð˜¸¥í¸ôàíô¤ì())½…Å×µ¸43ÍÁ•è5׎è)Q•±•›͹¥„


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