convert_copy.pass.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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>
  12. // tuple& operator=(const tuple<UTypes...>& u);
  13. // UNSUPPORTED: c++98, c++03
  14. #include <tuple>
  15. #include <string>
  16. #include <cassert>
  17. struct B
  18. {
  19. int id_;
  20. explicit B(int i = 0) : id_(i) {}
  21. };
  22. struct D
  23. : B
  24. {
  25. explicit D(int i = 0) : B(i) {}
  26. };
  27. int main()
  28. {
  29. {
  30. typedef std::tuple<double> T0;
  31. typedef std::tuple<int> T1;
  32. T0 t0(2.5);
  33. T1 t1;
  34. t1 = t0;
  35. assert(std::get<0>(t1) == 2);
  36. }
  37. {
  38. typedef std::tuple<double, char> T0;
  39. typedef std::tuple<int, int> T1;
  40. T0 t0(2.5, 'a');
  41. T1 t1;
  42. t1 = t0;
  43. assert(std::get<0>(t1) == 2);
  44. assert(std::get<1>(t1) == int('a'));
  45. }
  46. {
  47. typedef std::tuple<double, char, D> T0;
  48. typedef std::tuple<int, int, B> T1;
  49. T0 t0(2.5, 'a', D(3));
  50. T1 t1;
  51. t1 = t0;
  52. assert(std::get<0>(t1) == 2);
  53. assert(std::get<1>(t1) == int('a'));
  54. assert(std::get<2>(t1).id_ == 3);
  55. }
  56. {
  57. D d(3);
  58. D d2(2);
  59. typedef std::tuple<double, char, D&> T0;
  60. typedef std::tuple<int, int, B&> T1;
  61. T0 t0(2.5, 'a', d2);
  62. T1 t1(1.5, 'b', d);
  63. t1 = t0;
  64. assert(std::get<0>(t1) == 2);
  65. assert(std::get<1>(t1) == int('a'));
  66. assert(std::get<2>(t1).id_ == 2);
  67. }
  68. }