non_member_swap.pass.cpp 1.7 KB

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