]> gcc.gnu.org Git - gcc.git/blob - libstdc++/tests/tmap.cc
2c164c932a9744e326c4872e2a3d8bd32d3093d4
[gcc.git] / libstdc++ / tests / tmap.cc
1 #include <map.h>
2 #include <algo.h>
3 #include <iostream.h>
4 #include <function.h>
5
6 int SIZE;
7
8 #if 0
9 /* Crashes compiler */
10 #define int_less less<int>
11 #else
12 struct int_less {
13 bool operator() (int x, int y) const { return x < y; }
14 };
15 struct str_less {
16 bool operator() (char* x, char* y) const { return strcmp(x,y) < 0; }
17 };
18 #endif
19
20 #if 0
21 void add(int x[], int y[], map<int,int, int_less>& a)
22 {
23 for (int i = 0; i < SIZE; ++i) a[x[i]] = y[i];
24 }
25 #endif
26
27 int
28 main(int argv, char** argc)
29 {
30 #if 0
31 if (argv > 1)
32 {
33 SIZE = abs(atoi(argc[1]));
34 SIZE &= ~1;
35 }
36 else
37 SIZE = 100;
38 nums = new int[SIZE];
39 odds = new int[SIZE];
40 perm = new int[SIZE];
41 #endif
42
43 map<int, int, int_less> my_map;
44
45 map<char*, int, str_less> phones;
46
47 my_map[4] = 40;
48 my_map[2] = 20;
49
50 // The (char*) is needed because g++ doesn't
51 // convert char[] to char* in this context.
52 phones[(char*)"tom"] = 2345;
53 phones[(char*)"dick"] = 5678;
54 phones[(char*)"harry"] = 7654;
55
56 cout << "2 -> " << my_map[2] << endl;
57 cout << "4 -> " << my_map[4] << endl;
58
59 map<int, int, int_less>::iterator it = my_map.begin();
60 for ( ; it != my_map.end(); it++)
61 cout << "my_map[" << (*it).first << "] = " << (*it).second << endl;
62
63 map<char*, int, str_less>::iterator pit = phones.begin();
64 for ( ; pit != phones.end(); pit++)
65 cout << "phones[" << (*pit).first << "] = " << (*pit).second << endl;
66 }
67
68 template class __malloc_alloc_template<0>;
69 template class __default_alloc_template<false, 0>;
This page took 0.042265 seconds and 4 git commands to generate.