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 | //===----------------------------------------------------------------------===// |
8 | |
9 | // UNSUPPORTED: c++03 |
10 | |
11 | // <valarray> |
12 | |
13 | // template<class T> class valarray; |
14 | |
15 | // valarray& operator=(initializer_list<value_type> il); |
16 | |
17 | #include <valarray> |
18 | #include <cassert> |
19 | #include <cstddef> |
20 | |
21 | #include "test_macros.h" |
22 | |
23 | struct S |
24 | { |
25 | S() : x_(0) { default_ctor_called = true; } |
26 | S(int x) : x_(x) {} |
27 | int x_; |
28 | static bool default_ctor_called; |
29 | }; |
30 | |
31 | bool S::default_ctor_called = false; |
32 | |
33 | bool operator==(const S& lhs, const S& rhs) |
34 | { |
35 | return lhs.x_ == rhs.x_; |
36 | } |
37 | |
38 | int main(int, char**) |
39 | { |
40 | { |
41 | typedef int T; |
42 | T a[] = {1, 2, 3, 4, 5}; |
43 | const unsigned N = sizeof(a)/sizeof(a[0]); |
44 | std::valarray<T> v2; |
45 | v2 = {1, 2, 3, 4, 5}; |
46 | assert(v2.size() == N); |
47 | for (std::size_t i = 0; i < v2.size(); ++i) |
48 | assert(v2[i] == a[i]); |
49 | } |
50 | { |
51 | typedef double T; |
52 | T a[] = {1, 2.5, 3, 4.25, 5}; |
53 | const unsigned N = sizeof(a)/sizeof(a[0]); |
54 | std::valarray<T> v2; |
55 | v2 = {1, 2.5, 3, 4.25, 5}; |
56 | assert(v2.size() == N); |
57 | for (std::size_t i = 0; i < v2.size(); ++i) |
58 | assert(v2[i] == a[i]); |
59 | } |
60 | { |
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> v2(a, N-2); |
65 | v2 = {T(1), T(2), T(3), T(4), T(5)}; |
66 | assert(v2.size() == N); |
67 | for (unsigned i = 0; i < N; ++i) |
68 | { |
69 | assert(v2[i].size() == a[i].size()); |
70 | for (std::size_t j = 0; j < a[i].size(); ++j) |
71 | assert(v2[i][j] == a[i][j]); |
72 | } |
73 | } |
74 | { |
75 | typedef S T; |
76 | T a[] = {T(1), T(2), T(3), T(4), T(5)}; |
77 | const unsigned N = sizeof(a)/sizeof(a[0]); |
78 | std::valarray<T> v2; |
79 | v2 = {T(1), T(2), T(3), T(4), T(5)}; |
80 | assert(v2.size() == N); |
81 | for (std::size_t i = 0; i < v2.size(); ++i) |
82 | assert(v2[i] == a[i]); |
83 | assert(!S::default_ctor_called); |
84 | } |
85 | |
86 | return 0; |
87 | } |
88 | |