alloc_convert_copy.pass.cpp 2.6 KB

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