[multi_index_container] Using modify_key vs modify
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? Thanks, MK. -- Anand's signature
Muruganand Karthikeyan
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
; ... multi_t m=...; auto it=m.find(5); m.modify(it,[](X& x){x.n=8;});
is entirely equivalent to ... auto it=m.find(5); m.modify_key(it,[](int& n){n=8;}); Joaquín M López Muñoz Telefónica
participants (2)
-
Joaquin M López Muñoz
-
Muruganand Karthikeyan