blob: 8606611f6603c8853ec4c8ffe4bbad597d071b50 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
Howard Hinnantf5256e12010-05-11 21:36:01 +00003// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00007//
8//===----------------------------------------------------------------------===//
9
10// <utility>
11
Howard Hinnantc52f43e2010-08-22 00:59:46 +000012// template<class T>
13// requires MoveAssignable<T> && MoveConstructible<T>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000014// void
15// swap(T& a, T& b);
16
17#include <utility>
18#include <cassert>
Dan Albert1d4a1ed2016-05-25 22:36:09 -070019#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000020#include <memory>
21#endif
22
Dan Albert1d4a1ed2016-05-25 22:36:09 -070023void
24test()
25{
26 int i = 1;
27 int j = 2;
28 std::swap(i, j);
29 assert(i == 2);
30 assert(j == 1);
31}
32
33#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
34
35void
36test1()
37{
38 std::unique_ptr<int> i(new int(1));
39 std::unique_ptr<int> j(new int(2));
40 std::swap(i, j);
41 assert(*i == 2);
42 assert(*j == 1);
43}
44
45#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
46
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000047int main()
48{
Dan Albert1d4a1ed2016-05-25 22:36:09 -070049 test();
50#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
51 test1();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000052#endif
53}