Tag | stl

  1. C++ std::multimap and Equal Range

    Today I have encountered a problem: Given that there are multiple equivalent keys in an instance of std::multimap, how could we list all of the corresponding values? For example:

    #include <map>
    #include <iostream>
    
    int main() {
      std::multimap<int, int> xs;
      xs.insert(std::make_pair(1, 12));
      xs.insert …

    More

  2. C++ Associative Container and Iterator Validness

    I used to believe that iterators will be invalidated after calling the member functions insert() or erase() of containers. Thus, I would adopt a conservative approach:

    1. Create a temporary container.
    2. Copy the elements which I would like to keep to the temporary container.
    3. Swap the container.

    For example, to remove …

    More