Re: map/multimap/wildcards



I'm confused. How can I define two comparison objects in a multimap?

You cannot

I need to use the regular strcmp (compare the full length of string 1
to string 2) for inserting objects into the multimap.

Yes

I need to use the strncmp(a,b,N) with the match pattern (using the
length of the match pattern) for finding objects in the multimap.

No you don't. You use the regular strcmp() same as before. In fact, what
ever COMP method is in force for the multimap, you use the same thing. The
trick is you achieve the same objective by making use of what
lower_bound(), upper_bound(), equal_range() returns and _NOT_ by changing
your COMP method.

lower_bound() returns an iterator to the first position that the element
searched for can be inserted without disturbing the order.
upper_bound() returns an iterator to the last position that the element
searched for can be inserted without disturbing the order.
equal_range() does both and if the iterators returned are identical, no
element of the looked-for-value is present.

This behaviour allows you to look for non-exact matches => exactly what you
want.


Stephen Howe


.



Relevant Pages

  • multimap, avoiding duplicated key->value pairs
    ... I have a question regarding STL multimap. ... When I'm inserting new key value pairs, I need to ensure that those pairs ... 1=>10 is not okay. ...
    (comp.lang.cpp)
  • Re: [C++] Multimap interation
    ... > If I want to find a key in a multimap I can use find. ... just returns an iterator to *a* matching element ' if there ... for the sequence of identical keys. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: reverse_iterator and erase causes assertion with _Mycont is NULL
    ... You are probably thinking about inserting. ... Erasing ... invalidates iterators to the element being erased, ... reverse iterator 'rit' points to the n-th element, ...
    (microsoft.public.vc.stl)
  • [C++] Multimap interation
    ... If I want to find a key in a multimap I can use find. ... Is is the case that the iterator ... returns element in sorted key order and so I can iterate the remaining ... elements until the key changes? ...
    (alt.comp.lang.learn.c-cpp)

Loading