61023.cc 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // { dg-do run { target c++11 } }
  2. // Copyright (C) 2014-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. // 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 COPYING3. If not see
  15. // <http://www.gnu.org/licenses/>.
  16. #include <set>
  17. #include <stdexcept>
  18. struct Comparator
  19. {
  20. Comparator() : valid(false) { }
  21. explicit Comparator(bool) : valid(true) { }
  22. bool operator()(int i, int j) const
  23. {
  24. if (!valid)
  25. throw std::logic_error("Comparator is invalid");
  26. return i < j;
  27. }
  28. private:
  29. bool valid;
  30. };
  31. int main()
  32. {
  33. using test_type = std::set<int, Comparator>;
  34. Comparator cmp{true};
  35. test_type good{cmp};
  36. test_type s1;
  37. s1 = good; // copy-assign
  38. s1.insert(1);
  39. s1.insert(2);
  40. test_type s2;
  41. s2 = std::move(good); // move-assign
  42. s2.insert(1);
  43. s2.insert(2);
  44. }