contains.cc 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright (C) 2018-2022 Free Software Foundation, Inc.
  2. //
  3. // This file is part of the GNU ISO C++ Library. This library is free
  4. // software; you can redistribute it and/or modify it under the
  5. // terms of the GNU General Public License as published by the
  6. // Free Software Foundation; either version 3, or (at your option)
  7. // any later version.
  8. // This library is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. // You should have received a copy of the GNU General Public License along
  13. // with this library; see the file COPYING3. If not see
  14. // <http://www.gnu.org/licenses/>.
  15. // { dg-options "-std=gnu++2a" }
  16. // { dg-do run { target c++2a } }
  17. #include <set>
  18. #include <testsuite_hooks.h>
  19. void
  20. test01()
  21. {
  22. std::set<int> m;
  23. VERIFY( ! m.contains( 0 ) );
  24. VERIFY( ! m.contains( 1 ) );
  25. m.insert(0);
  26. VERIFY( m.contains( 0 ) );
  27. VERIFY( ! m.contains( 1 ) );
  28. m.insert(1);
  29. VERIFY( m.contains( 0 ) );
  30. VERIFY( m.contains( 1 ) );
  31. }
  32. struct Zero { };
  33. bool operator<(Zero, int i) { return 0 < i; }
  34. bool operator<(int i, Zero) { return i < 0; }
  35. struct One { };
  36. bool operator<(One, int i) { return 1 < i; }
  37. bool operator<(int i, One) { return i < 1; }
  38. void
  39. test02()
  40. {
  41. std::set<int, std::less<>> m;
  42. VERIFY( ! m.contains( Zero{} ) );
  43. VERIFY( ! m.contains( One{} ) );
  44. m.insert(0);
  45. VERIFY( m.contains( Zero{} ) );
  46. VERIFY( ! m.contains( One{} ) );
  47. m.insert(1);
  48. VERIFY( m.contains( Zero{} ) );
  49. VERIFY( m.contains( One{} ) );
  50. }
  51. int
  52. main()
  53. {
  54. test01();
  55. test02();
  56. }