typedef pair<unsigned char, unsigned char> pair_k;
map<unsigned char, pair_k> mapping;
Which will be used this way:
mapping[100] = make_pair(10,10);
Question is:
So, you can use pair as a key in a map as follows: map<pair<int,string> , long> mp; mp. insert(make_pair(make_pair(2,"me"),123456789);
A pair is a single unit with two members. A map has keys and values in it. So you can use pairs to fill up a map, the elements of the pair becoming key and value.
We generally see map being used for standard data types. We can also use map for pairs.
std:pair holds exactly two objects. std:map hold a collection of paired objects.
That looks ok to me. But note that this is not array access; it just looks like it because std::map
overloads operator[]
. If you do mapping.size()
afterwards, you will find that it will be 1
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With