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