iter_swap.pass.cpp 1009 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. // <algorithm>
  9. // template<Iterator Iter1, Iterator Iter2>
  10. // requires HasSwap<Iter1::reference, Iter2::reference>
  11. // void
  12. // iter_swap(Iter1 a, Iter2 b);
  13. #include <algorithm>
  14. #include <cassert>
  15. #include "test_macros.h"
  16. #if TEST_STD_VER > 17
  17. constexpr bool test_swap_constexpr()
  18. {
  19. int i = 1;
  20. int j = 2;
  21. std::iter_swap(&i, &j);
  22. return i == 2 && j == 1;
  23. }
  24. #endif // TEST_STD_VER > 17
  25. int main(int, char**)
  26. {
  27. int i = 1;
  28. int j = 2;
  29. std::iter_swap(&i, &j);
  30. assert(i == 2);
  31. assert(j == 1);
  32. #if TEST_STD_VER > 17
  33. static_assert(test_swap_constexpr());
  34. #endif // TEST_STD_VER > 17
  35. return 0;
  36. }