member_swap.pass.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 "test_macros.h"
  15. #include "MoveOnly.h"
  16. int main(int, char**)
  17. {
  18. {
  19. typedef std::tuple<> T;
  20. T t0;
  21. T t1;
  22. t0.swap(t1);
  23. }
  24. {
  25. typedef std::tuple<MoveOnly> T;
  26. T t0(MoveOnly(0));
  27. T t1(MoveOnly(1));
  28. t0.swap(t1);
  29. assert(std::get<0>(t0) == 1);
  30. assert(std::get<0>(t1) == 0);
  31. }
  32. {
  33. typedef std::tuple<MoveOnly, MoveOnly> T;
  34. T t0(MoveOnly(0), MoveOnly(1));
  35. T t1(MoveOnly(2), MoveOnly(3));
  36. t0.swap(t1);
  37. assert(std::get<0>(t0) == 2);
  38. assert(std::get<1>(t0) == 3);
  39. assert(std::get<0>(t1) == 0);
  40. assert(std::get<1>(t1) == 1);
  41. }
  42. {
  43. typedef std::tuple<MoveOnly, MoveOnly, MoveOnly> T;
  44. T t0(MoveOnly(0), MoveOnly(1), MoveOnly(2));
  45. T t1(MoveOnly(3), MoveOnly(4), MoveOnly(5));
  46. t0.swap(t1);
  47. assert(std::get<0>(t0) == 3);
  48. assert(std::get<1>(t0) == 4);
  49. assert(std::get<2>(t0) == 5);
  50. assert(std::get<0>(t1) == 0);
  51. assert(std::get<1>(t1) == 1);
  52. assert(std::get<2>(t1) == 2);
  53. }
  54. return 0;
  55. }