swap.pass.cpp 865 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. // <queue>
  9. // void swap(queue& q);
  10. #include <queue>
  11. #include <cassert>
  12. #include "test_macros.h"
  13. template <class C>
  14. C
  15. make(int n)
  16. {
  17. C c;
  18. for (int i = 0; i < n; ++i)
  19. c.push(i);
  20. return c;
  21. }
  22. int main(int, char**)
  23. {
  24. std::queue<int> q1 = make<std::queue<int> >(5);
  25. std::queue<int> q2 = make<std::queue<int> >(10);
  26. std::queue<int> q1_save = q1;
  27. std::queue<int> q2_save = q2;
  28. q1.swap(q2);
  29. assert(q1 == q2_save);
  30. assert(q2 == q1_save);
  31. return 0;
  32. }