convert_copy.pass.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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... UTypes> tuple(const tuple<UTypes...>& u);
  12. // UNSUPPORTED: c++98, c++03
  13. #include <tuple>
  14. #include <utility>
  15. #include <string>
  16. #include <cassert>
  17. #include "test_macros.h"
  18. struct Explicit {
  19. int value;
  20. explicit Explicit(int x) : value(x) {}
  21. };
  22. struct Implicit {
  23. int value;
  24. Implicit(int x) : value(x) {}
  25. };
  26. struct B
  27. {
  28. int id_;
  29. explicit B(int i) : id_(i) {}
  30. };
  31. struct D
  32. : B
  33. {
  34. explicit D(int i) : B(i) {}
  35. };
  36. #if TEST_STD_VER > 11
  37. struct A
  38. {
  39. int id_;
  40. constexpr A(int i) : id_(i) {}
  41. friend constexpr bool operator==(const A& x, const A& y) {return x.id_ == y.id_;}
  42. };
  43. struct C
  44. {
  45. int id_;
  46. constexpr explicit C(int i) : id_(i) {}
  47. friend constexpr bool operator==(const C& x, const C& y) {return x.id_ == y.id_;}
  48. };
  49. #endif
  50. int main()
  51. {
  52. {
  53. typedef std::tuple<long> T0;
  54. typedef std::tuple<long long> T1;
  55. T0 t0(2);
  56. T1 t1 = t0;
  57. assert(std::get<0>(t1) == 2);
  58. }
  59. #if TEST_STD_VER > 11
  60. {
  61. typedef std::tuple<int> T0;
  62. typedef std::tuple<A> T1;
  63. constexpr T0 t0(2);
  64. constexpr T1 t1 = t0;
  65. static_assert(std::get<0>(t1) == 2, "");
  66. }
  67. {
  68. typedef std::tuple<int> T0;
  69. typedef std::tuple<C> T1;
  70. constexpr T0 t0(2);
  71. constexpr T1 t1{t0};
  72. static_assert(std::get<0>(t1) == C(2), "");
  73. }
  74. #endif
  75. {
  76. typedef std::tuple<long, char> T0;
  77. typedef std::tuple<long long, int> T1;
  78. T0 t0(2, 'a');
  79. T1 t1 = t0;
  80. assert(std::get<0>(t1) == 2);
  81. assert(std::get<1>(t1) == int('a'));
  82. }
  83. {
  84. typedef std::tuple<long, char, D> T0;
  85. typedef std::tuple<long long, int, B> T1;
  86. T0 t0(2, 'a', D(3));
  87. T1 t1 = t0;
  88. assert(std::get<0>(t1) == 2);
  89. assert(std::get<1>(t1) == int('a'));
  90. assert(std::get<2>(t1).id_ == 3);
  91. }
  92. {
  93. D d(3);
  94. typedef std::tuple<long, char, D&> T0;
  95. typedef std::tuple<long long, int, B&> T1;
  96. T0 t0(2, 'a', d);
  97. T1 t1 = t0;
  98. d.id_ = 2;
  99. assert(std::get<0>(t1) == 2);
  100. assert(std::get<1>(t1) == int('a'));
  101. assert(std::get<2>(t1).id_ == 2);
  102. }
  103. {
  104. typedef std::tuple<long, char, int> T0;
  105. typedef std::tuple<long long, int, B> T1;
  106. T0 t0(2, 'a', 3);
  107. T1 t1(t0);
  108. assert(std::get<0>(t1) == 2);
  109. assert(std::get<1>(t1) == int('a'));
  110. assert(std::get<2>(t1).id_ == 3);
  111. }
  112. {
  113. const std::tuple<int> t1(42);
  114. std::tuple<Explicit> t2(t1);
  115. assert(std::get<0>(t2).value == 42);
  116. }
  117. {
  118. const std::tuple<int> t1(42);
  119. std::tuple<Implicit> t2 = t1;
  120. assert(std::get<0>(t2).value == 42);
  121. }
  122. }