blob: b1209c3c3651bc202a309aaa216aab0d66bf38d1 [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<ValueType T, size_t N>
13// requires Swappable<T>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000014// void
15// swap(T (&a)[N], T (&b)[N]);
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[3] = {1, 2, 3};
27 int j[3] = {4, 5, 6};
28 std::swap(i, j);
29 assert(i[0] == 4);
30 assert(i[1] == 5);
31 assert(i[2] == 6);
32 assert(j[0] == 1);
33 assert(j[1] == 2);
34 assert(j[2] == 3);
35}
36
37#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
38
39void
40test1()
41{
42 std::unique_ptr<int> i[3];
43 for (int k = 0; k < 3; ++k)
44 i[k].reset(new int(k+1));
45 std::unique_ptr<int> j[3];
46 for (int k = 0; k < 3; ++k)
47 j[k].reset(new int(k+4));
48 std::swap(i, j);
49 assert(*i[0] == 4);
50 assert(*i[1] == 5);
51 assert(*i[2] == 6);
52 assert(*j[0] == 1);
53 assert(*j[1] == 2);
54 assert(*j[2] == 3);
55}
56
57#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000058
59int main()
60{
Dan Albert1d4a1ed2016-05-25 22:36:09 -070061 test();
62#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
63 test1();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000064#endif
65}