allocs.pass.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is dual licensed under the MIT and the University of Illinois Open
  6. // Source Licenses. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. // UNSUPPORTED: c++98, c++03
  10. // <memory>
  11. // template <class OuterAlloc, class... InnerAllocs>
  12. // class scoped_allocator_adaptor
  13. // template <class OuterA2>
  14. // scoped_allocator_adaptor(OuterA2&& outerAlloc,
  15. // const InnerAllocs& ...innerAllocs);
  16. #include <scoped_allocator>
  17. #include <cassert>
  18. #include "allocators.h"
  19. int main()
  20. {
  21. {
  22. typedef std::scoped_allocator_adaptor<A1<int>> A;
  23. A1<int> a3(3);
  24. A a(a3);
  25. assert(a.outer_allocator() == A1<int>(3));
  26. assert(a.inner_allocator() == a);
  27. assert(A1<int>::copy_called == true);
  28. assert(A1<int>::move_called == false);
  29. }
  30. A1<int>::copy_called = false;
  31. {
  32. typedef std::scoped_allocator_adaptor<A1<int>> A;
  33. A a(A1<int>(3));
  34. assert(a.outer_allocator() == A1<int>(3));
  35. assert(a.inner_allocator() == a);
  36. assert(A1<int>::copy_called == false);
  37. assert(A1<int>::move_called == true);
  38. }
  39. A1<int>::move_called = false;
  40. {
  41. typedef std::scoped_allocator_adaptor<A1<int>, A2<int>> A;
  42. A1<int> a4(4);
  43. A a(a4, A2<int>(5));
  44. assert(A1<int>::copy_called == true);
  45. assert(A1<int>::move_called == false);
  46. assert(A2<int>::copy_called == true);
  47. assert(A2<int>::move_called == false);
  48. assert(a.outer_allocator() == A1<int>(4));
  49. assert(a.inner_allocator() == std::scoped_allocator_adaptor<A2<int>>(A2<int>(5)));
  50. }
  51. A1<int>::copy_called = false;
  52. A1<int>::move_called = false;
  53. A2<int>::copy_called = false;
  54. A2<int>::move_called = false;
  55. {
  56. typedef std::scoped_allocator_adaptor<A1<int>, A2<int>> A;
  57. A a(A1<int>(4), A2<int>(5));
  58. assert(A1<int>::copy_called == false);
  59. assert(A1<int>::move_called == true);
  60. assert(A2<int>::copy_called == true);
  61. assert(A2<int>::move_called == false);
  62. assert(a.outer_allocator() == A1<int>(4));
  63. assert(a.inner_allocator() == std::scoped_allocator_adaptor<A2<int>>(A2<int>(5)));
  64. }
  65. A1<int>::copy_called = false;
  66. A1<int>::move_called = false;
  67. A2<int>::copy_called = false;
  68. A2<int>::move_called = false;
  69. A1<int>::move_called = false;
  70. {
  71. typedef std::scoped_allocator_adaptor<A1<int>, A2<int>, A3<int>> A;
  72. A1<int> a4(4);
  73. A a(a4, A2<int>(5), A3<int>(6));
  74. assert(A1<int>::copy_called == true);
  75. assert(A1<int>::move_called == false);
  76. assert(A2<int>::copy_called == true);
  77. assert(A2<int>::move_called == false);
  78. assert(A3<int>::copy_called == true);
  79. assert(A3<int>::move_called == false);
  80. assert(a.outer_allocator() == A1<int>(4));
  81. assert((a.inner_allocator() ==
  82. std::scoped_allocator_adaptor<A2<int>, A3<int>>(A2<int>(5), A3<int>(6))));
  83. }
  84. A1<int>::copy_called = false;
  85. A1<int>::move_called = false;
  86. A2<int>::copy_called = false;
  87. A2<int>::move_called = false;
  88. A3<int>::copy_called = false;
  89. A3<int>::move_called = false;
  90. {
  91. typedef std::scoped_allocator_adaptor<A1<int>, A2<int>, A3<int>> A;
  92. A a(A1<int>(4), A2<int>(5), A3<int>(6));
  93. assert(A1<int>::copy_called == false);
  94. assert(A1<int>::move_called == true);
  95. assert(A2<int>::copy_called == true);
  96. assert(A2<int>::move_called == false);
  97. assert(A3<int>::copy_called == true);
  98. assert(A3<int>::move_called == false);
  99. assert(a.outer_allocator() == A1<int>(4));
  100. assert((a.inner_allocator() ==
  101. std::scoped_allocator_adaptor<A2<int>, A3<int>>(A2<int>(5), A3<int>(6))));
  102. }
  103. // Test for LWG2782
  104. {
  105. static_assert(!std::is_convertible<A1<int>, A2<int>>::value, "");
  106. static_assert(!std::is_convertible<
  107. std::scoped_allocator_adaptor<A1<int>>,
  108. std::scoped_allocator_adaptor<A2<int>>>::value, "");
  109. }
  110. }