|
Boost Users : |
Subject: Re: [Boost-users] Boost:multi-index Question on usage of project &modify_key
From: joaquin_at_[hidden]
Date: 2009-01-15 02:30:06
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 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