swap.pass.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. // UNSUPPORTED: c++98, c++03
  9. // <filesystem>
  10. // void swap(path& lhs, path& rhs) noexcept;
  11. #include "filesystem_include.hpp"
  12. #include <type_traits>
  13. #include <cassert>
  14. #include "test_macros.h"
  15. #include "count_new.hpp"
  16. #include "filesystem_test_helper.hpp"
  17. // NOTE: this is tested in path.members/path.modifiers via the member swap.
  18. int main(int, char**)
  19. {
  20. using namespace fs;
  21. const char* value1 = "foo/bar/baz";
  22. const char* value2 = "_THIS_IS_LONG_THIS_IS_LONG_THIS_IS_LONG_THIS_IS_LONG_THIS_IS_LONG_THIS_IS_LONG_THIS_IS_LONG";
  23. path p1(value1);
  24. path p2(value2);
  25. {
  26. using namespace std; using namespace fs;
  27. ASSERT_NOEXCEPT(swap(p1, p2));
  28. ASSERT_SAME_TYPE(void, decltype(swap(p1, p2)));
  29. }
  30. {
  31. DisableAllocationGuard g;
  32. using namespace std;
  33. using namespace fs;
  34. swap(p1, p2);
  35. assert(p1.native() == value2);
  36. assert(p2.native() == value1);
  37. swap(p1, p2);
  38. assert(p1.native() == value1);
  39. assert(p2.native() == value2);
  40. }
  41. return 0;
  42. }