|
Boost Users : |
From: JOAQUIN M. LOPEZ MUÑOZ (joaquin_at_[hidden])
Date: 2008-08-12 14:31:14
Hi Ramesh,
________________________________
De: boost-users-bounces_at_[hidden] [boost-users-bounces_at_[hidden]] En nombre de Ramesh [rramesh1_at_[hidden]]
Enviado el: martes, 12 de agosto de 2008 7:40
Para: boost-users_at_[hidden]
Asunto: [Boost-users] Multi-index container (Modifying non-unique key in the container)
>
> Hi.
>
> I am using boost multi-index container for storing objects of type class A, in the class key1 &
> Key 3 are unique and key2 is non-unique. I try to insert objects of type A and it works fine.
> No issues.
>
> At some point after the insertion, I wish to modify the key2 to 20 in the container. Can I do this
> with modify? If yes How do I define the iterator (since I need to do a find based on key1 but
> modify key2 in the container)
You have two options:
1. Use modify(), which is passed the entire element rather than the key, and
modify key2 at your pleasure.
2. Project the key1-iterator to a key2-iterator using the projection facilities:
http://www.boost.org/libs/multi_index/doc/tutorial/basics.html#projection
and then use modify_key() with the key2-iterator.
BTW, I've noticed that you're wrapping the A objects into a DataMap class
that, oddily enough, replicates the key1, key2 and key3 members. Why aren't
you using A members directly thus disposing of the DataMap wrapper?
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