ctor_copy_alloc.pass.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 Alloc>
  11. // stack(const stack& q, const Alloc& a);
  12. #include <stack>
  13. #include <cassert>
  14. #include "../../../../test_allocator.h"
  15. template <class C>
  16. C
  17. make(int n)
  18. {
  19. C c;
  20. for (int i = 0; i < n; ++i)
  21. c.push_back(int(i));
  22. return c;
  23. }
  24. typedef std::deque<int, test_allocator<int> > C;
  25. template <class T>
  26. struct test
  27. : public std::stack<T, C>
  28. {
  29. typedef std::stack<T, C> base;
  30. typedef test_allocator<int> allocator_type;
  31. typedef typename base::container_type container_type;
  32. explicit test(const allocator_type& a) : base(a) {}
  33. test(const container_type& c, const allocator_type& a) : base(c, a) {}
  34. test(const test& q, const allocator_type& a) : base(q, a) {}
  35. allocator_type get_allocator() {return this->c.get_allocator();}
  36. };
  37. int main()
  38. {
  39. test<int> q(make<C>(5), test_allocator<int>(4));
  40. test<int> q2(q, test_allocator<int>(5));
  41. assert(q2.get_allocator() == test_allocator<int>(5));
  42. assert(q2.size() == 5);
  43. }