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 
9 // <valarray>
10 
11 // template<class T> class valarray;
12 
13 // template<class T>
14 //   void
15 //   swap(valarray<T>& x, valarray<T>& y);
16 
17 #include <valarray>
18 #include <cassert>
19 #include <cstddef>
20 
21 #include "test_macros.h"
22 
main(int,char **)23 int main(int, char**)
24 {
25     {
26         typedef int T;
27         T a1[] = {1, 2, 3, 4, 5};
28         T a2[] = {6, 7, 8, 9, 10, 11, 12};
29         const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
30         const unsigned N2 = sizeof(a2)/sizeof(a2[0]);
31         std::valarray<T> v1(a1, N1);
32         std::valarray<T> v2(a2, N2);
33         std::valarray<T> v1_save = v1;
34         std::valarray<T> v2_save = v2;
35         swap(v1, v2);
36         assert(v1.size() == v2_save.size());
37         for (std::size_t i = 0; i < v1.size(); ++i)
38             assert(v1[i] == v2_save[i]);
39         assert(v2.size() == v1_save.size());
40         for (std::size_t i = 0; i < v2.size(); ++i)
41             assert(v2[i] == v1_save[i]);
42     }
43     {
44         typedef int T;
45         T a1[] = {1, 2, 3, 4, 5};
46         const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
47         std::valarray<T> v1(a1, N1);
48         std::valarray<T> v2;
49         std::valarray<T> v1_save = v1;
50         std::valarray<T> v2_save = v2;
51         swap(v1, v2);
52         assert(v1.size() == v2_save.size());
53         for (std::size_t i = 0; i < v1.size(); ++i)
54             assert(v1[i] == v2_save[i]);
55         assert(v2.size() == v1_save.size());
56         for (std::size_t i = 0; i < v2.size(); ++i)
57             assert(v2[i] == v1_save[i]);
58     }
59     {
60         typedef int T;
61         T a2[] = {6, 7, 8, 9, 10, 11, 12};
62         const unsigned N2 = sizeof(a2)/sizeof(a2[0]);
63         std::valarray<T> v1;
64         std::valarray<T> v2(a2, N2);
65         std::valarray<T> v1_save = v1;
66         std::valarray<T> v2_save = v2;
67         swap(v1, v2);
68         assert(v1.size() == v2_save.size());
69         for (std::size_t i = 0; i < v1.size(); ++i)
70             assert(v1[i] == v2_save[i]);
71         assert(v2.size() == v1_save.size());
72         for (std::size_t i = 0; i < v2.size(); ++i)
73             assert(v2[i] == v1_save[i]);
74     }
75     {
76         typedef int T;
77         std::valarray<T> v1;
78         std::valarray<T> v2;
79         std::valarray<T> v1_save = v1;
80         std::valarray<T> v2_save = v2;
81         swap(v1, v2);
82         assert(v1.size() == v2_save.size());
83         for (std::size_t i = 0; i < v1.size(); ++i)
84             assert(v1[i] == v2_save[i]);
85         assert(v2.size() == v1_save.size());
86         for (std::size_t i = 0; i < v2.size(); ++i)
87             assert(v2[i] == v1_save[i]);
88     }
89 
90   return 0;
91 }
92