• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // <valarray>
11 
12 // template <class T> class mask_array
13 
14 // void mask_array& operator=(const mask_array& ma) const;
15 
16 #include <valarray>
17 #include <cassert>
18 
main()19 int main()
20 {
21     {
22     int a1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
23     const std::size_t N1 = sizeof(a1)/sizeof(a1[0]);
24     bool b1[N1] = {true,  false, false, true,  true,  false,
25                    false, true,  false, false, false, true};
26     int a2[] = {-1, -2, -3, -4, -5, -6, -7, -8};
27     const std::size_t N2 = sizeof(a2)/sizeof(a2[0]);
28     bool b2[N2] = {true,  false, true, true,
29                    false, false, true, true};
30     std::valarray<int> v1(a1, N1);
31     const std::valarray<int> v2(a2, N2);
32     std::valarray<bool> vb1(b1, N1);
33     std::valarray<bool> vb2(b2, N2);
34     v1[vb1] = v2[vb2];
35     assert(v1.size() == 16);
36     assert(v1[ 0] == -1);
37     assert(v1[ 1] ==  1);
38     assert(v1[ 2] ==  2);
39     assert(v1[ 3] == -3);
40     assert(v1[ 4] == -4);
41     assert(v1[ 5] ==  5);
42     assert(v1[ 6] ==  6);
43     assert(v1[ 7] == -7);
44     assert(v1[ 8] ==  8);
45     assert(v1[ 9] ==  9);
46     assert(v1[10] == 10);
47     assert(v1[11] == -8);
48     assert(v1[12] == 12);
49     assert(v1[13] == 13);
50     assert(v1[14] == 14);
51     assert(v1[15] == 15);
52     }
53     // Test return value of assignment
54     {
55     int a1[] = {0, 1, 2};
56     int a2[] = {3, 4, 5};
57     bool b1[] = {true, false, true};
58     std::valarray<int> v1(a1, 3);
59     std::valarray<int> v2(a2, 3);
60     std::valarray<bool> const vb1(b1, 3);
61     std::mask_array<int> m1 = v1[vb1];
62     std::mask_array<int> const m2 = v2[vb1];
63     std::mask_array<int> const & r = (m1 = m2);
64     assert(&r == &m1);
65     }
66 }
67