forked from pezy/CppPrimer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex11_9_10.cpp
38 lines (33 loc) · 1.04 KB
/
ex11_9_10.cpp
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
//! @Alan
//!
//! Exercise 11.9:
//! Define a map that associates words with a list of
//! line numbers on which the word might occur.
//!
//! Exercise 11.10:
//! Could we define a map from vector<int>::iterator
//! to int? What about from list<int>::iterator to int?
//! In each case, if not, why not?
// vector<int>::iterator to int is ok ,because < is defined
// list<int>::iterator to int is not ok,as no < is defined.
#include <iostream>
#include <map>
#include <string>
#include <algorithm>
#include <list>
int main()
{
//! ex 11.9
std::map<std::string, std::list<std::size_t>> m;
//! ex 11.10
//! can be declared.
std::map<std::vector<int>::iterator, int> mv;
std::map<std::list<int>::iterator, int> ml;
std::vector<int> vi;
mv.insert(std::pair<std::vector<int>::iterator, int>(vi.begin(), 0));
//! but when using this one the compiler complained that
//! error: no match for 'operator<' in '__x < __y'
std::list<int> li;
ml.insert(std::pair<std::list<int>::iterator, int>(li.begin(), 0));
return 0;
}