]>
gcc.gnu.org Git - gcc.git/blob - libstdc++/tests/tmap.cc
2c164c932a9744e326c4872e2a3d8bd32d3093d4
10 #define int_less less<int>
13 bool operator() (int x
, int y
) const { return x
< y
; }
16 bool operator() (char* x
, char* y
) const { return strcmp(x
,y
) < 0; }
21 void add(int x
[], int y
[], map
<int,int, int_less
>& a
)
23 for (int i
= 0; i
< SIZE
; ++i
) a
[x
[i
]] = y
[i
];
28 main(int argv
, char** argc
)
33 SIZE
= abs(atoi(argc
[1]));
43 map
<int, int, int_less
> my_map
;
45 map
<char*, int, str_less
> phones
;
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;
56 cout
<< "2 -> " << my_map
[2] << endl
;
57 cout
<< "4 -> " << my_map
[4] << endl
;
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
;
63 map
<char*, int, str_less
>::iterator pit
= phones
.begin();
64 for ( ; pit
!= phones
.end(); pit
++)
65 cout
<< "phones[" << (*pit
).first
<< "] = " << (*pit
).second
<< endl
;
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.