#include <map>
#include <ctime>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>

struct MyObject
{
    std::string name;
    int information;

    MyObject(const std::string& name, int information)
    : name(name), information(information) {}
};

int main()
{
    std::srand(std::time(0));

    std::vector<MyObject> dataVec;
    std::multimap<std::string, MyObject*> dataMap;

    // Give each object a random letter
    // between A-J as a name and some data
    for(auto i = 0; i < 10; ++i)
        dataVec.emplace_back(std::string(1, 'A' + std::rand() % 10), i);

    // Fill dataMap from dataVec
    for(auto&& data: dataVec)
        dataMap.emplace(data.name, &data);

    // Select the correct type for calling the equal_range function
    decltype(dataMap.equal_range("")) range;

    // iterate through multimap's elements (by key)
    for(auto i = dataMap.begin(); i != dataMap.end(); i = range.second)
    {
        // Get the range of the current key
        range = dataMap.equal_range(i->first);

        // Now print out that whole range
        for(auto d = range.first; d != range.second; ++d)
            std::cout << d->first << ": " << d->second->information << '\n';
    }
}

