/gcc-4.3/libstdc++-v3/testsuite/23_containers/multimap/modifiers/swap/2.cc

https://bitbucket.org/pizzafactory/blackfin-toolchain · C++ · 147 lines · 102 code · 27 blank · 18 comment · 18 complexity · ed827ab2438039fa07aea7cacb4d1f24 MD5 · raw file

  1. // 2005-12-20 Paolo Carlini <pcarlini@suse.de>
  2. // Copyright (C) 2005 Free Software Foundation, Inc.
  3. //
  4. // This file is part of the GNU ISO C++ Library. This library is free
  5. // software; you can redistribute it and/or modify it under the
  6. // terms of the GNU General Public License as published by the
  7. // Free Software Foundation; either version 2, or (at your option)
  8. // any later version.
  9. // This library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. // You should have received a copy of the GNU General Public License along
  14. // with this library; see the file COPYING. If not, write to the Free
  15. // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  16. // USA.
  17. // 23.3.2 multimap::swap
  18. #include <map>
  19. #include <testsuite_hooks.h>
  20. #include <testsuite_allocator.h>
  21. // uneq_allocator as a non-empty allocator.
  22. void
  23. test01()
  24. {
  25. bool test __attribute__((unused)) = true;
  26. using namespace std;
  27. typedef pair<const char, int> my_pair;
  28. typedef __gnu_test::uneq_allocator<my_pair> my_alloc;
  29. typedef multimap<char, int, less<char>, my_alloc> my_mmap;
  30. const char title01[] = "Rivers of sand";
  31. const char title02[] = "Concret PH";
  32. const char title03[] = "Sonatas and Interludes for Prepared Piano";
  33. const char title04[] = "never as tired as when i'm waking up";
  34. const size_t N1 = sizeof(title01);
  35. const size_t N2 = sizeof(title02);
  36. const size_t N3 = sizeof(title03);
  37. const size_t N4 = sizeof(title04);
  38. multimap<char, int> mmap01_ref;
  39. for (size_t i = 0; i < N1; ++i)
  40. mmap01_ref.insert(my_pair(title01[i], i));
  41. multimap<char, int> mmap02_ref;
  42. for (size_t i = 0; i < N2; ++i)
  43. mmap02_ref.insert(my_pair(title02[i], i));
  44. multimap<char, int> mmap03_ref;
  45. for (size_t i = 0; i < N3; ++i)
  46. mmap03_ref.insert(my_pair(title03[i], i));
  47. multimap<char, int> mmap04_ref;
  48. for (size_t i = 0; i < N4; ++i)
  49. mmap04_ref.insert(my_pair(title04[i], i));
  50. my_mmap::size_type size01, size02;
  51. my_alloc alloc01(1);
  52. my_mmap mmap01(less<char>(), alloc01);
  53. size01 = mmap01.size();
  54. my_mmap mmap02(less<char>(), alloc01);
  55. size02 = mmap02.size();
  56. mmap01.swap(mmap02);
  57. VERIFY( mmap01.size() == size02 );
  58. VERIFY( mmap01.empty() );
  59. VERIFY( mmap02.size() == size01 );
  60. VERIFY( mmap02.empty() );
  61. my_mmap mmap03(less<char>(), alloc01);
  62. size01 = mmap03.size();
  63. my_mmap mmap04(mmap02_ref.begin(), mmap02_ref.end(), less<char>(), alloc01);
  64. size02 = mmap04.size();
  65. mmap03.swap(mmap04);
  66. VERIFY( mmap03.size() == size02 );
  67. VERIFY( equal(mmap03.begin(), mmap03.end(), mmap02_ref.begin()) );
  68. VERIFY( mmap04.size() == size01 );
  69. VERIFY( mmap04.empty() );
  70. my_mmap mmap05(mmap01_ref.begin(), mmap01_ref.end(), less<char>(), alloc01);
  71. size01 = mmap05.size();
  72. my_mmap mmap06(mmap02_ref.begin(), mmap02_ref.end(), less<char>(), alloc01);
  73. size02 = mmap06.size();
  74. mmap05.swap(mmap06);
  75. VERIFY( mmap05.size() == size02 );
  76. VERIFY( equal(mmap05.begin(), mmap05.end(), mmap02_ref.begin()) );
  77. VERIFY( mmap06.size() == size01 );
  78. VERIFY( equal(mmap06.begin(), mmap06.end(), mmap01_ref.begin()) );
  79. my_mmap mmap07(mmap01_ref.begin(), mmap01_ref.end(), less<char>(), alloc01);
  80. size01 = mmap07.size();
  81. my_mmap mmap08(mmap03_ref.begin(), mmap03_ref.end(), less<char>(), alloc01);
  82. size02 = mmap08.size();
  83. mmap07.swap(mmap08);
  84. VERIFY( mmap07.size() == size02 );
  85. VERIFY( equal(mmap07.begin(), mmap07.end(), mmap03_ref.begin()) );
  86. VERIFY( mmap08.size() == size01 );
  87. VERIFY( equal(mmap08.begin(), mmap08.end(), mmap01_ref.begin()) );
  88. my_mmap mmap09(mmap03_ref.begin(), mmap03_ref.end(), less<char>(), alloc01);
  89. size01 = mmap09.size();
  90. my_mmap mmap10(mmap04_ref.begin(), mmap04_ref.end(), less<char>(), alloc01);
  91. size02 = mmap10.size();
  92. mmap09.swap(mmap10);
  93. VERIFY( mmap09.size() == size02 );
  94. VERIFY( equal(mmap09.begin(), mmap09.end(), mmap04_ref.begin()) );
  95. VERIFY( mmap10.size() == size01 );
  96. VERIFY( equal(mmap10.begin(), mmap10.end(), mmap03_ref.begin()) );
  97. my_mmap mmap11(mmap04_ref.begin(), mmap04_ref.end(), less<char>(), alloc01);
  98. size01 = mmap11.size();
  99. my_mmap mmap12(mmap01_ref.begin(), mmap01_ref.end(), less<char>(), alloc01);
  100. size02 = mmap12.size();
  101. mmap11.swap(mmap12);
  102. VERIFY( mmap11.size() == size02 );
  103. VERIFY( equal(mmap11.begin(), mmap11.end(), mmap01_ref.begin()) );
  104. VERIFY( mmap12.size() == size01 );
  105. VERIFY( equal(mmap12.begin(), mmap12.end(), mmap04_ref.begin()) );
  106. my_mmap mmap13(mmap03_ref.begin(), mmap03_ref.end(), less<char>(), alloc01);
  107. size01 = mmap13.size();
  108. my_mmap mmap14(mmap03_ref.begin(), mmap03_ref.end(), less<char>(), alloc01);
  109. size02 = mmap14.size();
  110. mmap13.swap(mmap14);
  111. VERIFY( mmap13.size() == size02 );
  112. VERIFY( equal(mmap13.begin(), mmap13.end(), mmap03_ref.begin()) );
  113. VERIFY( mmap14.size() == size01 );
  114. VERIFY( equal(mmap14.begin(), mmap14.end(), mmap03_ref.begin()) );
  115. }
  116. int main()
  117. {
  118. test01();
  119. return 0;
  120. }