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