Re: Problems with std::map.insert() and std::map.find()
acehreli@gmail.com wrote:
On Dec 19, 6:45 pm, "(2b|!2b)==?" <void-s...@ursa-major.com> wrote:
template<class T1, class T2>
class PointerMap
class RepositoryKey
Could you please also show how you use these classes. Especially a few
lines of code that demonstrates the problem...
Ali
A snippet of how I am using the classes:
void foobar(Rows& rows)
{
typedef PointerMap<RepositoryKey, MyValueClass> DataDictonary ;
MyValueClass * myValue = 0;
long xch, ic, fq ;
std::string symb;
MyDataRowIterator it = rows.begin();
for (; it != rows.end(); ++it)
{
xch = (*it).xch;
ic = (*it).ic;
symb = (*it).symb ;
fq = (*it).fq;
//Does this 4-tuple exist in repository?
RepositoryKey key(xch, ic, symb, fq);
DataDictonary::iterator iter ;
//NOTE: find() only works for first item inserted, so I have to
//resort to manually iterating through all of the items in the map
//and doing a comparison .... (the code below is how I want to use it
though ...)
if ( ( iter = dictionary.find()) != dictionary.end() )
myValue = (*iter).second ;
else
{
//create a new value for this key
if ( (myValue = CreateValue()) )
{
//Now store the data in the dictionary
//NOTE: Only the first insert works !
dictionary.insert(key, myValue);
}
else
throw std::bad_alloc();
}
// Do something with the value ....
}
}