alloc_convert_move.pass.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. // <tuple>
  10. // template <class... Types> class tuple;
  11. // template <class Alloc, class... UTypes>
  12. // tuple(allocator_arg_t, const Alloc& a, tuple<UTypes...>&&);
  13. // UNSUPPORTED: c++98, c++03
  14. #include <tuple>
  15. #include <string>
  16. #include <memory>
  17. #include <cassert>
  18. #include "allocators.h"
  19. #include "../alloc_first.h"
  20. #include "../alloc_last.h"
  21. struct B
  22. {
  23. int id_;
  24. explicit B(int i) : id_(i) {}
  25. virtual ~B() {}
  26. };
  27. struct D
  28. : B
  29. {
  30. explicit D(int i) : B(i) {}
  31. };
  32. struct Explicit {
  33. int value;
  34. explicit Explicit(int x) : value(x) {}
  35. };
  36. struct Implicit {
  37. int value;
  38. Implicit(int x) : value(x) {}
  39. };
  40. int main()
  41. {
  42. {
  43. typedef std::tuple<int> T0;
  44. typedef std::tuple<alloc_first> T1;
  45. T0 t0(2);
  46. alloc_first::allocator_constructed = false;
  47. T1 t1(std::allocator_arg, A1<int>(5), std::move(t0));
  48. assert(alloc_first::allocator_constructed);
  49. assert(std::get<0>(t1) == 2);
  50. }
  51. {
  52. typedef std::tuple<std::unique_ptr<D>> T0;
  53. typedef std::tuple<std::unique_ptr<B>> T1;
  54. T0 t0(std::unique_ptr<D>(new D(3)));
  55. T1 t1(std::allocator_arg, A1<int>(5), std::move(t0));
  56. assert(std::get<0>(t1)->id_ == 3);
  57. }
  58. {
  59. typedef std::tuple<int, std::unique_ptr<D>> T0;
  60. typedef std::tuple<alloc_first, std::unique_ptr<B>> T1;
  61. T0 t0(2, std::unique_ptr<D>(new D(3)));
  62. alloc_first::allocator_constructed = false;
  63. T1 t1(std::allocator_arg, A1<int>(5), std::move(t0));
  64. assert(alloc_first::allocator_constructed);
  65. assert(std::get<0>(t1) == 2);
  66. assert(std::get<1>(t1)->id_ == 3);
  67. }
  68. {
  69. typedef std::tuple<int, int, std::unique_ptr<D>> T0;
  70. typedef std::tuple<alloc_last, alloc_first, std::unique_ptr<B>> T1;
  71. T0 t0(1, 2, std::unique_ptr<D>(new D(3)));
  72. alloc_first::allocator_constructed = false;
  73. alloc_last::allocator_constructed = false;
  74. T1 t1(std::allocator_arg, A1<int>(5), std::move(t0));
  75. assert(alloc_first::allocator_constructed);
  76. assert(alloc_last::allocator_constructed);
  77. assert(std::get<0>(t1) == 1);
  78. assert(std::get<1>(t1) == 2);
  79. assert(std::get<2>(t1)->id_ == 3);
  80. }
  81. {
  82. std::tuple<int> t1(42);
  83. std::tuple<Explicit> t2{std::allocator_arg, std::allocator<void>{}, std::move(t1)};
  84. assert(std::get<0>(t2).value == 42);
  85. }
  86. {
  87. std::tuple<int> t1(42);
  88. std::tuple<Implicit> t2 = {std::allocator_arg, std::allocator<void>{}, std::move(t1)};
  89. assert(std::get<0>(t2).value == 42);
  90. }
  91. }