I have declared array of sets
std::set<md_core::Sample *> _SessionSet[MAX_SESSIONS];
Now I wrote two functions
void insertIntoTrdSessionSet(unsigned char index, md_core::Sample *sample)
{
_SessionSet[index].insert(sample);
}
bool removeFromTrdSessionSet(md_core::Sample *sample, unsigned char i = MAX_SESSIONS)
{
if(i != MAX_SESSIONS)
{
if(_SessionSet[i].erase(sample))
return true;
}
else
{
for(i = 0; i < MAX_SESSIONS ; i++)
{
if(_SessionSet[i].erase(sample))
{
return true;
}
}
}
return false;
}
Now i extract a value from set one by one and try to delete but it shows that value is not present in the struct
for(i = 0; i < MAX_SESSIONS ; i++)
{
if(i != pMsg->_Session)
{
std::set<Sample *>::iterator it = pSub->_SessionSet[i].begin();
for(;it != pSub->_SessionSet[i].end(); it++)
{
sample = *it;
//now call delete for the sample
if(!pSub->removeFromTrdSessionSet(sample, i))
{
logV(MD_WARN_MSG, "No such sample %d to delete from odrders map for session %u", sample, index);
}
}
}
}