31
|
1 |
|
|
2 |
// STLport regression testsuite component.
|
|
3 |
// To compile as a separate example, please #define MAIN.
|
|
4 |
|
|
5 |
#include <map>
|
|
6 |
#include <iostream>
|
|
7 |
|
|
8 |
#ifdef MAIN
|
|
9 |
#define mmap1_test main
|
|
10 |
#endif
|
|
11 |
|
|
12 |
#if !defined (STLPORT) || defined(__STL_USE_NAMESPACES)
|
|
13 |
using namespace std;
|
|
14 |
#endif
|
|
15 |
int mmap1_test(int, char**)
|
|
16 |
{
|
|
17 |
cout<<"Results of mmap1_test:"<<endl;
|
|
18 |
typedef multimap<char, int, less<char> > mmap;
|
|
19 |
mmap m;
|
|
20 |
int failures = 0;
|
|
21 |
|
|
22 |
cout << "count('X') = " << m.count('X') << endl;
|
|
23 |
if(m.count('X') != 0)
|
|
24 |
failures++;
|
|
25 |
|
|
26 |
m.insert(pair<const char, int>('X', 10)); // Standard way.
|
|
27 |
cout << "count('X') = " << m.count('X') << endl;
|
|
28 |
// m.insert('X', 20); // Non-standard, but very convenient!
|
|
29 |
if(m.count('X') != 1)
|
|
30 |
failures++;
|
|
31 |
|
|
32 |
m.insert(pair<const char, int>('X', 20)); // jbuck: standard way
|
|
33 |
cout << "count('X') = " << m.count('X') << endl;
|
|
34 |
// m.insert('Y', 32);
|
|
35 |
if(m.count('X') != 2)
|
|
36 |
failures++;
|
|
37 |
m.insert(pair<const char, int>('Y', 32)); // jbuck: standard way
|
|
38 |
mmap::iterator i = m.find('X'); // Find first match.
|
|
39 |
while(i != m.end()) // Loop until end is reached.
|
|
40 |
{
|
|
41 |
cout <<(*i).first << " -> " <<(*i).second << endl;
|
|
42 |
i++;
|
|
43 |
}
|
|
44 |
int count = m.erase('X');
|
|
45 |
cout << "Erased " << count << " items" << endl;
|
|
46 |
if (count != 2)
|
|
47 |
failures++;
|
|
48 |
|
|
49 |
return failures;
|
|
50 |
}
|