ctor_rqueue_alloc.pass.cpp 1.7 KB

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