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