Re: Problems with std::map.insert() and std::map.find()

Discussion in 'C++' started by acehreli@gmail.com, Dec 21, 2008.

  1. Guest

    On Dec 19, 6:45 pm, "(2b|!2b)==?" <> 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
    , Dec 21, 2008
    #1
    1. Advertising

  2. red floyd Guest

    (2b|!2b)==? wrote:
    > wrote:
    >> On Dec 19, 6:45 pm, "(2b|!2b)==?" <> 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() )


    dictionary.find() what?

    > 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 ....
    > }
    > }
    red floyd, Dec 21, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    3
    Views:
    921
    Howard Hinnant
    Apr 20, 2005
  2. Replies:
    1
    Views:
    448
  3. Thomas J. Gritzan
    Replies:
    6
    Views:
    1,018
    James Kanze
    Dec 22, 2008
  4. James Kanze
    Replies:
    0
    Views:
    1,998
    James Kanze
    Dec 21, 2008
  5. Ricardo
    Replies:
    8
    Views:
    423
    Joe Greer
    Jul 8, 2009
Loading...

Share This Page