Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / numerics / numarray / template.valarray / valarray.assign / copy_assign.pass.cpp
blobb216c67c172adc7440848afdd6b24ffa9a3d6714
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 //===----------------------------------------------------------------------===//
9 // <valarray>
11 // template<class T> class valarray;
13 // valarray& operator=(const valarray& v);
15 #include <valarray>
16 #include <cassert>
17 #include <cstddef>
19 #include "test_macros.h"
21 struct S
23 S() : x_(0) { default_ctor_called = true; }
24 S(int x) : x_(x) {}
25 int x_;
26 static bool default_ctor_called;
29 bool S::default_ctor_called = false;
31 bool operator==(const S& lhs, const S& rhs)
33 return lhs.x_ == rhs.x_;
36 int main(int, char**)
39 typedef int T;
40 T a[] = {1, 2, 3, 4, 5};
41 const unsigned N = sizeof(a)/sizeof(a[0]);
42 std::valarray<T> v(a, N);
43 std::valarray<T> v2;
44 v2 = v;
45 assert(v2.size() == v.size());
46 for (std::size_t i = 0; i < v2.size(); ++i)
47 assert(v2[i] == v[i]);
50 typedef double T;
51 T a[] = {1, 2.5, 3, 4.25, 5};
52 const unsigned N = sizeof(a)/sizeof(a[0]);
53 std::valarray<T> v(a, N);
54 std::valarray<T> v2;
55 v2 = v;
56 assert(v2.size() == v.size());
57 for (std::size_t i = 0; i < v2.size(); ++i)
58 assert(v2[i] == v[i]);
61 typedef std::valarray<double> T;
62 T a[] = {T(1), T(2), T(3), T(4), T(5)};
63 const unsigned N = sizeof(a)/sizeof(a[0]);
64 std::valarray<T> v(a, N);
65 std::valarray<T> v2(a, N-2);
66 v2 = v;
67 assert(v2.size() == v.size());
68 for (unsigned i = 0; i < N; ++i)
70 assert(v2[i].size() == v[i].size());
71 for (std::size_t j = 0; j < v[i].size(); ++j)
72 assert(v2[i][j] == v[i][j]);
76 typedef S T;
77 T a[] = {T(1), T(2), T(3), T(4), T(5)};
78 const unsigned N = sizeof(a)/sizeof(a[0]);
79 std::valarray<T> v(a, N);
80 std::valarray<T> v2;
81 v2 = v;
82 assert(v2.size() == v.size());
83 for (std::size_t i = 0; i < v2.size(); ++i)
84 assert(v2[i] == v[i]);
85 assert(!S::default_ctor_called);
88 return 0;