|
Boost Users : |
From: Patel Priyank-PPATEL1 (priyankpatel_at_[hidden])
Date: 2006-04-18 09:04:55
Hi Joaquin,
Thanks for all your replies. Let me read carefully the link you sent out.
I will write you back in case of any more questions. Thanks for this great library,
it is really helpful.
Thanks again,
Priyank
-----Original Message-----
From: boost-users-bounces_at_[hidden] [mailto:boost-users-bounces_at_[hidden]] On Behalf Of Joaquín Mª López Muñoz
Sent: Tuesday, April 18, 2006 2:21 AM
To: boost-users_at_[hidden]
Subject: Re: [Boost-users] [multi_index] Sorting object based on some specified criteria!!
Patel Priyank-PPATEL1 ha escrito:
> Hi Joaquin,
>
> First of all thanks for your time and response. I have it working as follows, but seems I have to recalculate iterators if in case I later on modify group associated with that access point. Is there any way that iterators will know automatically update when I update access point in future to some other group?
> Let me know if you have come across that one. I am going to look in your code in detail and get back to you in case of any questions.
Hello Priyank, there's an issue in your code:
> // change paging group from access point 4
> a4->pg(2);
This is incorrect and can lead to hard-to-detect failures later on during the execution of the program: basically, you're changing an element key "under the table", that is, without the multi-index container having a chance to notice, which directly breaks the internal invariants the container relies on. Under usual conditions it is difficult to change a key in such a way, because the elements of a multi-index container are treated as const, but here you can easily get by because it is pointers that you are storing.
The proper way to modify an element is by using replace, modify of modify_key, as explained in
http://boost.org/libs/multi_index/doc/tutorial.html#ord_updating
In your case, instead of what you've got you could write the following:
// get an iterator to a4. You could also have stored those iterators in the
// first place when inserting the elements.
Access_Points::iterator it=pool.find(4);
// change paging group from access point 4
pool.modify(it,boost::bind(&Access_point::pg,_1,2));
By using modify(), the multi-index container is on control of the updating operation, and will rearrange a4 according to its new paging group.
> // NEED TO RECALCULATE ITERATORS
> boost::tuples::tie(pg0, pg1) = get<paging_group>
> (pool).equal_range(1);
As for your original question, yes, you've got to recalculate these iterators in the general case, as elements might have been moved around, inserted or
deleted: for instance, if the element originally pointed to by pg0 had been deleted, pg0 would not even be valid after that.
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
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