Imported Upstream version 4.8.1
[platform/upstream/gcc48.git] / libstdc++-v3 / testsuite / 23_containers / multimap / operations / 1.cc
1 // 2006-11-25  Paolo Carlini  <pcarlini@suse.de>
2
3 // Copyright (C) 2006-2013 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library.  This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
9 // any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING3.  If not see
18 // <http://www.gnu.org/licenses/>.
19 //
20
21 #include <map>
22 #include <testsuite_hooks.h>
23
24 // A few tests for equal_range, in the occasion of libstdc++/29385.
25 void test01()
26 {
27   bool test __attribute__((unused)) = true;
28   using namespace std;
29
30   multimap<int, int> mm0;
31   typedef multimap<int, int>::iterator iterator;
32   pair<iterator, iterator> pp0;
33   typedef multimap<int, int>::value_type value_type;
34
35   pp0 = mm0.equal_range(1);
36   VERIFY( mm0.count(1) == 0 );
37   VERIFY( pp0.first == mm0.end() );
38   VERIFY( pp0.second == mm0.end() );
39
40   iterator iter0 = mm0.insert(value_type(1, 1));
41   iterator iter1 = mm0.insert(value_type(2, 2));
42   iterator iter2 = mm0.insert(value_type(3, 3));
43  
44   pp0 = mm0.equal_range(2);
45   VERIFY( mm0.count(2) == 1 );
46   VERIFY( *pp0.first == value_type(2, 2) );
47   VERIFY( *pp0.second == value_type(3, 3) );
48   VERIFY( pp0.first == iter1 );
49   VERIFY( --pp0.first == iter0 );  
50   VERIFY( pp0.second == iter2 );
51
52   mm0.insert(value_type(3, 4));
53   iterator iter3 = mm0.insert(value_type(3, 5));
54   iterator iter4 = mm0.insert(value_type(4, 6));
55
56   pp0 = mm0.equal_range(3);
57   VERIFY( mm0.count(3) == 3 );
58   VERIFY( *pp0.first == value_type(3, 3) );
59   VERIFY( *pp0.second == value_type(4, 6) );
60   VERIFY( pp0.first == iter2 );
61   VERIFY( --pp0.first == iter1 );  
62   VERIFY( pp0.second == iter4 );
63
64   iterator iter5 = mm0.insert(value_type(0, 7));
65   mm0.insert(value_type(1, 8));
66   mm0.insert(value_type(1, 9));
67   mm0.insert(value_type(1, 10));
68
69   pp0 = mm0.equal_range(1);
70   VERIFY( mm0.count(1) == 4 );
71   VERIFY( *pp0.first == value_type(1, 1) );
72   VERIFY( *pp0.second == value_type(2, 2) );
73   VERIFY( pp0.first == iter0 );
74   VERIFY( --pp0.first == iter5 );  
75   VERIFY( pp0.second == iter1 );
76
77   iterator iter6 = mm0.insert(value_type(5, 11));
78   mm0.insert(value_type(5, 12));
79   mm0.insert(value_type(5, 13));
80
81   pp0 = mm0.equal_range(5);
82   VERIFY( mm0.count(5) == 3 );
83   VERIFY( *pp0.first == value_type(5, 11) );
84   VERIFY( pp0.first == iter6 );
85   VERIFY( --pp0.first == iter4 );  
86   VERIFY( pp0.second == mm0.end() );
87
88   mm0.insert(value_type(4, 14));
89   mm0.insert(value_type(4, 15));
90   mm0.insert(value_type(4, 16));
91
92   pp0 = mm0.equal_range(4);
93   VERIFY( mm0.count(4) == 4 );  
94   VERIFY( *pp0.first == value_type(4, 6) );
95   VERIFY( *pp0.second == value_type(5, 11) );  
96   VERIFY( pp0.first == iter4 );
97   VERIFY( --pp0.first == iter3 );  
98   VERIFY( pp0.second == iter6 );
99
100   mm0.insert(value_type(0, 17));
101   iterator iter7 = mm0.insert(value_type(0, 18));
102   mm0.insert(value_type(1, 19));
103
104   pp0 = mm0.equal_range(0);
105   VERIFY( mm0.count(0) == 3 );  
106   VERIFY( *pp0.first == value_type(0, 7) );
107   VERIFY( *pp0.second == value_type(1, 1) );  
108   VERIFY( pp0.first == iter5 );
109   VERIFY( pp0.first == mm0.begin() );
110   VERIFY( pp0.second == iter0 );
111
112   pp0 = mm0.equal_range(1);
113   VERIFY( mm0.count(1) == 5 );  
114   VERIFY( *pp0.first == value_type(1, 1) );
115   VERIFY( *pp0.second == value_type(2, 2) );  
116   VERIFY( pp0.first == iter0 );
117   VERIFY( --pp0.first == iter7 );
118   VERIFY( pp0.second == iter1 );
119 }
120
121 int
122 main()
123 {
124   test01();
125   return 0;
126 }