1.cc 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. // 2006-11-25 Paolo Carlini <pcarlini@suse.de>
  2. // Copyright (C) 2006-2022 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 3, or (at your option)
  8. // any later version.
  9. //
  10. // This library is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. // GNU General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU General Public License along
  16. // with this library; see the file COPYING3. If not see
  17. // <http://www.gnu.org/licenses/>.
  18. //
  19. #include <set>
  20. #include <testsuite_hooks.h>
  21. // A few tests for equal_range, in the occasion of libstdc++/29385.
  22. void test01()
  23. {
  24. using namespace std;
  25. set<int> s0;
  26. typedef set<int>::iterator iterator;
  27. typedef set<int>::const_iterator const_iterator;
  28. typedef pair<iterator, bool> insert_return_type;
  29. pair<iterator, iterator> pp0;
  30. pp0 = s0.equal_range(1);
  31. VERIFY( s0.count(1) == 0 );
  32. VERIFY( pp0.first == s0.end() );
  33. VERIFY( pp0.second == s0.end() );
  34. insert_return_type irt0 = s0.insert(1);
  35. insert_return_type irt1 = s0.insert(2);
  36. insert_return_type irt2 = s0.insert(3);
  37. pp0 = s0.equal_range(2);
  38. VERIFY( s0.count(2) == 1 );
  39. VERIFY( *pp0.first == 2 );
  40. VERIFY( *pp0.second == 3 );
  41. VERIFY( pp0.first == irt1.first );
  42. VERIFY( --pp0.first == irt0.first );
  43. VERIFY( pp0.second == irt2.first );
  44. s0.insert(3);
  45. insert_return_type irt3 = s0.insert(3);
  46. insert_return_type irt4 = s0.insert(4);
  47. pp0 = s0.equal_range(3);
  48. VERIFY( s0.count(3) == 1 );
  49. VERIFY( *pp0.first == 3 );
  50. VERIFY( *pp0.second == 4 );
  51. VERIFY( pp0.first == irt2.first );
  52. VERIFY( --pp0.first == irt1.first );
  53. VERIFY( pp0.second == irt4.first );
  54. insert_return_type irt5 = s0.insert(0);
  55. s0.insert(1);
  56. s0.insert(1);
  57. s0.insert(1);
  58. pp0 = s0.equal_range(1);
  59. VERIFY( s0.count(1) == 1 );
  60. VERIFY( *pp0.first == 1 );
  61. VERIFY( *pp0.second == 2 );
  62. VERIFY( pp0.first == irt0.first );
  63. VERIFY( --pp0.first == irt5.first );
  64. VERIFY( pp0.second == irt1.first );
  65. insert_return_type irt6 = s0.insert(5);
  66. s0.insert(5);
  67. s0.insert(5);
  68. pp0 = s0.equal_range(5);
  69. VERIFY( s0.count(5) == 1 );
  70. VERIFY( *pp0.first == 5 );
  71. VERIFY( pp0.first == irt6.first );
  72. VERIFY( --pp0.first == irt4.first );
  73. VERIFY( pp0.second == s0.end() );
  74. s0.insert(4);
  75. s0.insert(4);
  76. s0.insert(4);
  77. pp0 = s0.equal_range(4);
  78. VERIFY( s0.count(4) == 1 );
  79. VERIFY( *pp0.first == 4 );
  80. VERIFY( *pp0.second == 5 );
  81. VERIFY( pp0.first == irt4.first );
  82. VERIFY( --pp0.first == irt3.first );
  83. VERIFY( pp0.second == irt6.first );
  84. s0.insert(0);
  85. insert_return_type irt7 = s0.insert(0);
  86. s0.insert(1);
  87. pp0 = s0.equal_range(0);
  88. VERIFY( s0.count(0) == 1 );
  89. VERIFY( *pp0.first == 0 );
  90. VERIFY( *pp0.second == 1 );
  91. VERIFY( pp0.first == irt5.first );
  92. VERIFY( pp0.first == s0.begin() );
  93. VERIFY( pp0.second == irt0.first );
  94. const set<int>& s1 = s0;
  95. pair<const_iterator, const_iterator> pp1 = s1.equal_range(1);
  96. VERIFY( s1.count(1) == 1 );
  97. VERIFY( *pp1.first == 1 );
  98. VERIFY( *pp1.second == 2 );
  99. VERIFY( pp1.first == irt0.first );
  100. VERIFY( --pp1.first == irt7.first );
  101. VERIFY( pp1.second == irt1.first );
  102. }
  103. int
  104. main()
  105. {
  106. test01();
  107. return 0;
  108. }