swap_array.pass.cpp revision b64f8b07c104c6cc986570ac8ee0ed16a9f23976
1//===----------------------------------------------------------------------===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10// <utility>
11
12// template<ValueType T, size_t N>
13//   requires Swappable<T>
14//   void
15//   swap(T (&a)[N], T (&b)[N]);
16
17#include <utility>
18#include <cassert>
19#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
20#include <memory>
21#endif
22
23void
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
58
59int main()
60{
61    test();
62#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
63    test1();
64#endif
65}
66