ctor_container_alloc.pass.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. // <queue>
  10. // template <class Alloc>
  11. // queue(const container_type& c, const Alloc& a);
  12. #include <queue>
  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(i);
  22. return c;
  23. }
  24. typedef std::deque<int, test_allocator<int> > C;
  25. struct test
  26. : public std::queue<int, C>
  27. {
  28. typedef std::queue<int, C> base;
  29. explicit test(const test_allocator<int>& a) : base(a) {}
  30. test(const container_type& c, const test_allocator<int>& a) : base(c, a) {}
  31. #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
  32. test(container_type&& c, const test_allocator<int>& a) : base(std::move(c), a) {}
  33. test(test&& q, const test_allocator<int>& a) : base(std::move(q), a) {}
  34. #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
  35. test_allocator<int> get_allocator() {return c.get_allocator();}
  36. };
  37. int main()
  38. {
  39. C d = make<C>(5);
  40. test q(d, test_allocator<int>(4));
  41. assert(q.get_allocator() == test_allocator<int>(4));
  42. assert(q.size() == 5);
  43. for (int i = 0; i < d.size(); ++i)
  44. {
  45. assert(q.front() == d[i]);
  46. q.pop();
  47. }
  48. }