swap.pass.cpp 867 B

12345678910111213141516171819202122232425262728293031323334353637
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. // <stack>
  10. // template <class T, class Container>
  11. // void swap(stack<T, Container>& x, stack<T, Container>& y);
  12. #include <stack>
  13. #include <cassert>
  14. template <class C>
  15. C
  16. make(int n)
  17. {
  18. C c;
  19. for (int i = 0; i < n; ++i)
  20. c.push(i);
  21. return c;
  22. }
  23. int main()
  24. {
  25. std::stack<int> q1 = make<std::stack<int> >(5);
  26. std::stack<int> q2 = make<std::stack<int> >(10);
  27. std::stack<int> q1_save = q1;
  28. std::stack<int> q2_save = q2;
  29. swap(q1, q2);
  30. assert(q1 == q2_save);
  31. assert(q2 == q1_save);
  32. }