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 // valarray& operator=(const 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 a[] = {1, 2, 3, 4, 5};
25 const unsigned N = sizeof(a)/sizeof(a[0]);
26 std::valarray<T> v(a, N);
27 std::valarray<T> v2;
28 v2 = v;
29 assert(v2.size() == v.size());
30 for (std::size_t i = 0; i < v2.size(); ++i)
31 assert(v2[i] == v[i]);
32 }
33 {
34 typedef double T;
35 T a[] = {1, 2.5, 3, 4.25, 5};
36 const unsigned N = sizeof(a)/sizeof(a[0]);
37 std::valarray<T> v(a, N);
38 std::valarray<T> v2;
39 v2 = v;
40 assert(v2.size() == v.size());
41 for (std::size_t i = 0; i < v2.size(); ++i)
42 assert(v2[i] == v[i]);
43 }
44 {
45 typedef std::valarray<double> T;
46 T a[] = {T(1), T(2), T(3), T(4), T(5)};
47 const unsigned N = sizeof(a)/sizeof(a[0]);
48 std::valarray<T> v(a, N);
49 std::valarray<T> v2(a, N-2);
50 v2 = v;
51 assert(v2.size() == v.size());
52 for (unsigned i = 0; i < N; ++i)
53 {
54 assert(v2[i].size() == v[i].size());
55 for (std::size_t j = 0; j < v[i].size(); ++j)
56 assert(v2[i][j] == v[i][j]);
57 }
58 }
59 }
60