dr130.cc 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // { dg-do run { target c++11 } }
  2. // 2008-07-22 Edward Smith-Rowland <3dw4rd@verizon.net>
  3. //
  4. // Copyright (C) 2009-2022 Free Software Foundation, Inc.
  5. //
  6. // This file is part of the GNU ISO C++ Library. This library is free
  7. // software; you can redistribute it and/or modify it under the
  8. // terms of the GNU General Public License as published by the
  9. // Free Software Foundation; either version 3, or (at your option)
  10. // any later version.
  11. //
  12. // This library is distributed in the hope that it will be useful,
  13. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. // GNU General Public License for more details.
  16. //
  17. // You should have received a copy of the GNU General Public License along
  18. // with this library; see the file COPYING3. If not see
  19. // <http://www.gnu.org/licenses/>.
  20. #include <set>
  21. #include <testsuite_hooks.h>
  22. // DR 130. Associative erase should return an iterator.
  23. void
  24. test01()
  25. {
  26. using namespace std;
  27. set<int> s0;
  28. typedef set<int>::iterator iterator;
  29. typedef set<int>::const_iterator const_iterator;
  30. typedef pair<iterator, bool> insert_return_type;
  31. s0.insert(1);
  32. insert_return_type irt1 = s0.insert(2);
  33. insert_return_type irt2 = s0.insert(3);
  34. iterator pos1 = s0.erase(irt1.first);
  35. VERIFY( pos1 == irt2.first );
  36. iterator pos2 = s0.erase(irt2.first);
  37. VERIFY( pos2 == s0.end() );
  38. }
  39. void
  40. test02()
  41. {
  42. using namespace std;
  43. set<int> s0;
  44. typedef set<int>::iterator iterator;
  45. typedef set<int>::const_iterator const_iterator;
  46. typedef pair<iterator, bool> insert_return_type;
  47. insert_return_type irt0 = s0.insert(1);
  48. s0.insert(2);
  49. insert_return_type irt2 = s0.insert(3);
  50. insert_return_type irt3 = s0.insert(4);
  51. iterator pos1 = s0.erase(irt0.first, irt2.first);
  52. VERIFY( pos1 == irt2.first );
  53. iterator pos2 = s0.erase(irt2.first, ++irt3.first);
  54. VERIFY( pos2 == s0.end() );
  55. }
  56. int
  57. main()
  58. {
  59. test01();
  60. test02();
  61. }