#include <algorithm>
#include <iostream>
#include <iterator>
#include <map>
#include <string>
#include <tuple>

using container_type = std::multimap<std::string, int>;

std::multimap<std::string, int> original_table =
{
    {"a", 1},
    {"c", 2},
    {"b", 3},
    {"b", 4},
    {"a", 5},
    {"b", 6}
};

void unique(container_type& container)
{
    for (auto iter = begin(container); iter != end(container); ++iter)
    {
        auto last = container.upper_bound(iter->first);
        container.erase(next(iter), last);
    }
}

template <typename container_t>
void print_associative(const container_t& c)
{
    for (auto& item : c)
        std::cout << item.first << ": " << item.second << '\n';
}

int main()
{
    container_type table(original_table);

    std::cout << "Before:\n";
    print_associative(table);


    unique(table);
    std::cout << "\nAfter:\n";
    print_associative(table);


    using key_type = container_type::key_type;
    using mapped_type = container_type::mapped_type;
    std::map<key_type, mapped_type> m(begin(original_table), end(original_table));

    std::cout << "\nMap:\n";
    print_associative(m);

    using value_type = container_type::value_type;
    auto value_equal = [](value_type& a, value_type&b) { return a.first == b.first; };

    container_type unique_copy_result;
    std::unique_copy(begin(original_table), end(original_table), 
                     std::inserter(unique_copy_result, begin(unique_copy_result)),
                     value_equal);

    std::cout << "\nUnique_copy:\n";
    print_associative(unique_copy_result);
}