ctor_container.pass.cpp 893 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. // <stack>
  9. // explicit stack(const container_type& c);
  10. #include <stack>
  11. #include <cassert>
  12. #include <cstddef>
  13. #include "test_macros.h"
  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_back(i);
  21. return c;
  22. }
  23. int main(int, char**)
  24. {
  25. std::deque<int> d = make<std::deque<int> >(5);
  26. std::stack<int> q(d);
  27. assert(q.size() == 5);
  28. for (std::size_t i = 0; i < d.size(); ++i)
  29. {
  30. assert(q.top() == d[d.size() - i - 1]);
  31. q.pop();
  32. }
  33. return 0;
  34. }