multimap array with same elements

Dear experts,

I have a doubt regarding mutlimap. Suppose I have filled the multimap with 5 pairs, but all are the same. For exmaple
std::multimap<int,int> mymm;

mymm.insert(make_pair(1,50));
mymm.insert(make_pair(1,50));
mymm.insert(make_pair(1,50));

here I am filling the multi map with the same pair thrice. In this case corresponding to the same key, the value is the same in all three cases. Will the multimap count this as one element or as three different elements? Is there any way to check if the elements are same or not ?
Try it and see?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
#include <map>

int main()
{
    std::multimap<int,int> mymm;
    
    mymm.insert(std::make_pair(1,50));
    mymm.insert(std::make_pair(1,50));
    mymm.insert(std::make_pair(1,50));    
    
    std::cout << "Size = " << mymm.size() << '\n';
    
    for (const auto & a : mymm)
        std::cout << a.first << ' ' << a.second << '\n';
}

Output:
Size = 3
1 50
1 50
1 50
With uniform initialization using initializer lists:
1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
#include <map>

int main()
{
    std::multimap<int,int> mymm {{1,50}, {1,50},{1,50}};

    std::cout << "Size = " << mymm.size() << '\n';

    for (const auto & a : mymm)
        std::cout << a.first << ' ' << a.second << '\n';
}
Topic archived. No new replies allowed.