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