| 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 | // <valarray> |
| 10 | |
| 11 | // template<class T> class valarray; |
| 12 | |
| 13 | // explicit valarray(size_t); |
| 14 | |
| 15 | #include <valarray> |
| 16 | #include <cassert> |
| 17 | |
| 18 | #include "test_macros.h" |
| 19 | |
| 20 | struct S { |
| 21 | S() : x(1) {} |
| 22 | ~S() { ++cnt_dtor; } |
| 23 | int x; |
| 24 | static std::size_t cnt_dtor; |
| 25 | }; |
| 26 | |
| 27 | size_t S::cnt_dtor = 0; |
| 28 | |
| 29 | int main(int, char**) |
| 30 | { |
| 31 | { |
| 32 | std::valarray<int> v(100); |
| 33 | assert(v.size() == 100); |
| 34 | for (int i = 0; i < 100; ++i) |
| 35 | assert(v[i] == 0); |
| 36 | } |
| 37 | { |
| 38 | std::valarray<double> v(100); |
| 39 | assert(v.size() == 100); |
| 40 | for (int i = 0; i < 100; ++i) |
| 41 | assert(v[i] == 0); |
| 42 | } |
| 43 | { |
| 44 | std::valarray<std::valarray<double> > v(100); |
| 45 | assert(v.size() == 100); |
| 46 | for (int i = 0; i < 100; ++i) |
| 47 | assert(v[i].size() == 0); |
| 48 | } |
| 49 | { |
| 50 | std::valarray<S> v(100); |
| 51 | assert(v.size() == 100); |
| 52 | for (int i = 0; i < 100; ++i) |
| 53 | assert(v[i].x == 1); |
| 54 | } |
| 55 | assert(S::cnt_dtor == 100); |
| 56 | |
| 57 | return 0; |
| 58 | } |
| 59 | |