xref: /llvm-project/libcxx/test/std/numerics/numarray/template.valarray/valarray.cons/size.pass.cpp (revision 57b08b0944046a6a57ee9b7b479181f548a5b9b4)
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 struct S {
19     S() : x(1) {}
20     ~S() { ++cnt_dtor; }
21     int x;
22     static size_t cnt_dtor;
23 };
24 
25 size_t S::cnt_dtor = 0;
26 
27 int main()
28 {
29     {
30         std::valarray<int> v(100);
31         assert(v.size() == 100);
32         for (int i = 0; i < 100; ++i)
33             assert(v[i] == 0);
34     }
35     {
36         std::valarray<double> v(100);
37         assert(v.size() == 100);
38         for (int i = 0; i < 100; ++i)
39             assert(v[i] == 0);
40     }
41     {
42         std::valarray<std::valarray<double> > v(100);
43         assert(v.size() == 100);
44         for (int i = 0; i < 100; ++i)
45             assert(v[i].size() == 0);
46     }
47     {
48         std::valarray<S> v(100);
49         assert(v.size() == 100);
50         for (int i = 0; i < 100; ++i)
51             assert(v[i].x == 1);
52     }
53     assert(S::cnt_dtor == 100);
54 }
55