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