member_swap.pass.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. // <tuple>
  9. // template <class... Types> class tuple;
  10. // void swap(tuple& rhs);
  11. // UNSUPPORTED: c++98, c++03
  12. #include <tuple>
  13. #include <cassert>
  14. #include "MoveOnly.h"
  15. int main(int, char**)
  16. {
  17. {
  18. typedef std::tuple<> T;
  19. T t0;
  20. T t1;
  21. t0.swap(t1);
  22. }
  23. {
  24. typedef std::tuple<MoveOnly> T;
  25. T t0(MoveOnly(0));
  26. T t1(MoveOnly(1));
  27. t0.swap(t1);
  28. assert(std::get<0>(t0) == 1);
  29. assert(std::get<0>(t1) == 0);
  30. }
  31. {
  32. typedef std::tuple<MoveOnly, MoveOnly> T;
  33. T t0(MoveOnly(0), MoveOnly(1));
  34. T t1(MoveOnly(2), MoveOnly(3));
  35. t0.swap(t1);
  36. assert(std::get<0>(t0) == 2);
  37. assert(std::get<1>(t0) == 3);
  38. assert(std::get<0>(t1) == 0);
  39. assert(std::get<1>(t1) == 1);
  40. }
  41. {
  42. typedef std::tuple<MoveOnly, MoveOnly, MoveOnly> T;
  43. T t0(MoveOnly(0), MoveOnly(1), MoveOnly(2));
  44. T t1(MoveOnly(3), MoveOnly(4), MoveOnly(5));
  45. t0.swap(t1);
  46. assert(std::get<0>(t0) == 3);
  47. assert(std::get<1>(t0) == 4);
  48. assert(std::get<2>(t0) == 5);
  49. assert(std::get<0>(t1) == 0);
  50. assert(std::get<1>(t1) == 1);
  51. assert(std::get<2>(t1) == 2);
  52. }
  53. return 0;
  54. }