|
Boost Users : |
Subject: Re: [Boost-users] Boost:multi-index Question on usage of project &modify_key
From: Ramesh (rramesh1_at_[hidden])
Date: 2009-01-15 19:09:27
Thank you, I wasnt checking the return from find, The assert helped me
locate the actual problem which was in another call.
On Wed, Jan 14, 2009 at 11:30 PM, <joaquin_at_[hidden]> wrote:
> Ramesh escribió:
>>
>> Hello.
>>
>> I am using projection technique & modify_key in one of my member
>> functions:
>>
>> Assuming I have the following data in the container:
>>
>> ObjId ObjIp ObjIndex pMyObj
>>
>> -------------------------------------------------------------------------------------
>> ID1 10.10.1.2 1 0x10239032
>> ID2 10.10.1.3 2 0x23423423
>> ID3 10.10.1.4 3 0x23132423
>>
>> The member function 'UpdateKeyObjId' accepts the value on column 3 as
>> key & changes the corresponding value
>> for the field in Column 1.
>>
>> My code seems to work fine for all rows except the last row. When I
>> use modify key on the last record, the app crashes at
>> the highlighted line. I am not sure if my usage of project &
>> modify_key right, could someone please point out if there
>> are any errors in the usage?
>>
>
> Hello Ramesh,
>
> At first sight your code appears correct. The only plausible way that I can
> figure out
> the offending statement can crash:
>
> return MyContainer.get<0>().modify_key(ObjIdit, ll::_1 = param_ObjId);
>
> happens if ObjIdit==MyContainer.end(). You can check this by placing an
> assertion
> before that:
>
> typedef tMyObjMap::index<ObjIndex>::type tMyObjMapByIndex;
> tMyObjMapByIndex& ObjIndex_index = MyContainer.get<ObjIndex>();
>
> tMyObjMap::index_iterator<ObjIndex>::type it =
> ObjIndex_index.find(param_ObjIndex);
>
> assert(it!=ObjIndex_index.end());
>
> ...
>
> If the assertion fails then there's simply no element with the given
> param_ObjIndex,
> which I guess you can trace back to some problem elsewhere in your program.
>
> HTH,
>
> 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