xref: /llvm-project/libcxx/test/std/numerics/numarray/template.valarray/valarray.cons/move.pass.cpp (revision 2df59c50688c122bbcae7467d3eaf862c3ea3088)
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++98, c++03
10 
11 // <valarray>
12 
13 // template<class T> class valarray;
14 
15 // valarray(const valarray<value_type>& v);
16 
17 #include <valarray>
18 #include <utility>
19 #include <cassert>
20 #include <cstddef>
21 
22 int main(int, char**)
23 {
24     {
25         typedef int T;
26         T a[] = {1, 2, 3, 4, 5};
27         const unsigned N = sizeof(a)/sizeof(a[0]);
28         std::valarray<T> v(a, N);
29         std::valarray<T> v2 = std::move(v);
30         assert(v2.size() == N);
31         assert(v.size() == 0);
32         for (std::size_t i = 0; i < v2.size(); ++i)
33             assert(v2[i] == a[i]);
34     }
35     {
36         typedef double T;
37         T a[] = {1, 2.5, 3, 4.25, 5};
38         const unsigned N = sizeof(a)/sizeof(a[0]);
39         std::valarray<T> v(a, N);
40         std::valarray<T> v2 = std::move(v);
41         assert(v2.size() == N);
42         assert(v.size() == 0);
43         for (std::size_t i = 0; i < v2.size(); ++i)
44             assert(v2[i] == a[i]);
45     }
46     {
47         typedef std::valarray<double> T;
48         T a[] = {T(1), T(2), T(3), T(4), T(5)};
49         const unsigned N = sizeof(a)/sizeof(a[0]);
50         std::valarray<T> v(a, N);
51         std::valarray<T> v2 = std::move(v);
52         assert(v2.size() == N);
53         assert(v.size() == 0);
54         for (unsigned i = 0; i < N; ++i)
55         {
56             assert(v2[i].size() == a[i].size());
57             for (std::size_t j = 0; j < v2[i].size(); ++j)
58                 assert(v2[i][j] == a[i][j]);
59         }
60     }
61 
62   return 0;
63 }
64