move.pass.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. // tuple(tuple&& u);
  12. #include <tuple>
  13. #include <utility>
  14. #include <cassert>
  15. #include "../MoveOnly.h"
  16. struct ConstructsWithTupleLeaf
  17. {
  18. ConstructsWithTupleLeaf() {}
  19. ConstructsWithTupleLeaf(ConstructsWithTupleLeaf const &) { assert(false); }
  20. ConstructsWithTupleLeaf(ConstructsWithTupleLeaf &&) {}
  21. template <class T>
  22. ConstructsWithTupleLeaf(T t)
  23. { assert(false); }
  24. };
  25. int main()
  26. {
  27. {
  28. typedef std::tuple<> T;
  29. T t0;
  30. T t = std::move(t0);
  31. }
  32. {
  33. typedef std::tuple<MoveOnly> T;
  34. T t0(MoveOnly(0));
  35. T t = std::move(t0);
  36. assert(std::get<0>(t) == 0);
  37. }
  38. {
  39. typedef std::tuple<MoveOnly, MoveOnly> T;
  40. T t0(MoveOnly(0), MoveOnly(1));
  41. T t = std::move(t0);
  42. assert(std::get<0>(t) == 0);
  43. assert(std::get<1>(t) == 1);
  44. }
  45. {
  46. typedef std::tuple<MoveOnly, MoveOnly, MoveOnly> T;
  47. T t0(MoveOnly(0), MoveOnly(1), MoveOnly(2));
  48. T t = std::move(t0);
  49. assert(std::get<0>(t) == 0);
  50. assert(std::get<1>(t) == 1);
  51. assert(std::get<2>(t) == 2);
  52. }
  53. // A bug in tuple caused __tuple_leaf to use its explicit converting constructor
  54. // as its move constructor. This tests that ConstructsWithTupleLeaf is not called
  55. // (w/ __tuple_leaf)
  56. {
  57. typedef std::tuple<ConstructsWithTupleLeaf> d_t;
  58. d_t d((ConstructsWithTupleLeaf()));
  59. d_t d2(static_cast<d_t &&>(d));
  60. }
  61. }