summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/tr1/6_containers/unordered_multiset/swap/1.cc
blob: 6099df801845dd29d7cf74a5cf9d594f60f4f152 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
// 2005-12-20  Paolo Carlini  <pcarlini@suse.de>

// Copyright (C) 2005-2015 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3.  If not see
// <http://www.gnu.org/licenses/>.

// 6.3.4.5 unordered_multiset::swap

#include <tr1/unordered_set>
#include <set>
#include <testsuite_hooks.h>
#include <testsuite_allocator.h>

// uneq_allocator as a non-empty allocator.
void
test01()
{
  bool test __attribute__((unused)) = true;
  using namespace std::tr1;
  using std::equal_to;
  using std::multiset;

  typedef __gnu_test::uneq_allocator<char> my_alloc;
  typedef unordered_multiset<char, hash<char>, equal_to<char>, my_alloc>
    my_umset;

  const char title01[] = "Rivers of sand";
  const char title02[] = "Concret PH";
  const char title03[] = "Sonatas and Interludes for Prepared Piano";
  const char title04[] = "never as tired as when i'm waking up";

  const size_t N1 = sizeof(title01);
  const size_t N2 = sizeof(title02);
  const size_t N3 = sizeof(title03);
  const size_t N4 = sizeof(title04);

  typedef multiset<char> my_mset;
  const my_mset mset01_ref(title01, title01 + N1);
  const my_mset mset02_ref(title02, title02 + N2);
  const my_mset mset03_ref(title03, title03 + N3);
  const my_mset mset04_ref(title04, title04 + N4);

  my_umset::size_type size01, size02;

  my_alloc alloc01(1);

  my_umset umset01(10, hash<char>(), equal_to<char>(), alloc01);
  size01 = umset01.size();
  my_umset umset02(10, hash<char>(), equal_to<char>(), alloc01);
  size02 = umset02.size();
  
  umset01.swap(umset02);
  VERIFY( umset01.size() == size02 );
  VERIFY( umset01.empty() );
  VERIFY( umset02.size() == size01 );
  VERIFY( umset02.empty() );

  my_umset umset03(10, hash<char>(), equal_to<char>(), alloc01);
  size01 = umset03.size();
  my_umset umset04(mset02_ref.begin(), mset02_ref.end(), 10, hash<char>(),
		   equal_to<char>(), alloc01);
  size02 = umset04.size();
  
  umset03.swap(umset04);
  VERIFY( umset03.size() == size02 );
  VERIFY( my_mset(umset03.begin(), umset03.end()) == mset02_ref );
  VERIFY( umset04.size() == size01 );
  VERIFY( umset04.empty() );
  
  my_umset umset05(mset01_ref.begin(), mset01_ref.end(), 10, hash<char>(),
		   equal_to<char>(), alloc01);
  size01 = umset05.size();
  my_umset umset06(mset02_ref.begin(), mset02_ref.end(), 10, hash<char>(),
		   equal_to<char>(), alloc01);
  size02 = umset06.size();
  
  umset05.swap(umset06);
  VERIFY( umset05.size() == size02 );
  VERIFY( my_mset(umset05.begin(), umset05.end()) == mset02_ref );
  VERIFY( umset06.size() == size01 );
  VERIFY( my_mset(umset06.begin(), umset06.end()) == mset01_ref );

  my_umset umset07(mset01_ref.begin(), mset01_ref.end(), 10, hash<char>(),
		   equal_to<char>(), alloc01);
  size01 = umset07.size();
  my_umset umset08(mset03_ref.begin(), mset03_ref.end(), 10, hash<char>(),
		   equal_to<char>(), alloc01);
  size02 = umset08.size();

  umset07.swap(umset08);
  VERIFY( umset07.size() == size02 );
  VERIFY( my_mset(umset07.begin(), umset07.end()) == mset03_ref );
  VERIFY( umset08.size() == size01 );
  VERIFY( my_mset(umset08.begin(), umset08.end()) == mset01_ref );

  my_umset umset09(mset03_ref.begin(), mset03_ref.end(), 10, hash<char>(),
		   equal_to<char>(), alloc01);
  size01 = umset09.size();
  my_umset umset10(mset04_ref.begin(), mset04_ref.end(), 10, hash<char>(),
		   equal_to<char>(), alloc01);
  size02 = umset10.size();

  umset09.swap(umset10);
  VERIFY( umset09.size() == size02 );
  VERIFY( my_mset(umset09.begin(), umset09.end()) == mset04_ref );
  VERIFY( umset10.size() == size01 );
  VERIFY( my_mset(umset10.begin(), umset10.end()) == mset03_ref );

  my_umset umset11(mset04_ref.begin(), mset04_ref.end(), 10, hash<char>(),
		   equal_to<char>(), alloc01);
  size01 = umset11.size();
  my_umset umset12(mset01_ref.begin(), mset01_ref.end(), 10, hash<char>(),
		   equal_to<char>(), alloc01);
  size02 = umset12.size();

  umset11.swap(umset12);
  VERIFY( umset11.size() == size02 );
  VERIFY( my_mset(umset11.begin(), umset11.end()) == mset01_ref );
  VERIFY( umset12.size() == size01 );
  VERIFY( my_mset(umset12.begin(), umset12.end()) == mset04_ref );

  my_umset umset13(mset03_ref.begin(), mset03_ref.end(), 10, hash<char>(),
		   equal_to<char>(), alloc01);
  size01 = umset13.size();
  my_umset umset14(mset03_ref.begin(), mset03_ref.end(), 10, hash<char>(),
		   equal_to<char>(), alloc01);
  size02 = umset14.size();

  umset13.swap(umset14);
  VERIFY( umset13.size() == size02 );
  VERIFY( my_mset(umset13.begin(), umset13.end()) == mset03_ref );
  VERIFY( umset14.size() == size01 );
  VERIFY( my_mset(umset14.begin(), umset14.end()) == mset03_ref );
}

int main()
{ 
  test01();
  return 0;
}