-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path20.1 InstantiatingMapMultimap.cpp
More file actions
40 lines (31 loc) · 1.11 KB
/
20.1 InstantiatingMapMultimap.cpp
File metadata and controls
40 lines (31 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include<map>
#include<string>
template<typename keyType>
struct ReverseSort
{
bool operator()(const keyType& key1, const keyType& key2)
{
return (key1 > key2);
}
};
int main ()
{
using namespace std;
// map and multimap key of type int to value of type string
map<int, string> mapIntToStr1;
multimap<int, string> mmapIntToStr1;
// map and multimap constructed as a copy of another
map<int, string> mapIntToStr2(mapIntToStr1);
multimap<int, string> mmapIntToStr2(mmapIntToStr1);
// map and multimap constructed given a part of another map or multimap
map<int, string> mapIntToStr3(mapIntToStr1.cbegin(),
mapIntToStr1.cend());
multimap<int, string> mmapIntToStr3(mmapIntToStr1.cbegin(),
mmapIntToStr1.cend());
// map and multimap with a predicate that inverses sort order
map<int, string, ReverseSort<int> > mapIntToStr4
(mapIntToStr1.cbegin(), mapIntToStr1.cend());
multimap<int, string, ReverseSort<int> > mmapIntToStr4
(mapIntToStr1.cbegin(), mapIntToStr1.cend());
return 0;
}