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 mask_array 12 13 // void mask_array& operator=(const mask_array& ma) const; 14 15 #include <valarray> 16 #include <cassert> 17 18 int main(int, char**) 19 { 20 { 21 int a1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; 22 const std::size_t N1 = sizeof(a1)/sizeof(a1[0]); 23 bool b1[N1] = {true, false, false, true, true, false, 24 false, true, false, false, false, true}; 25 int a2[] = {-1, -2, -3, -4, -5, -6, -7, -8}; 26 const std::size_t N2 = sizeof(a2)/sizeof(a2[0]); 27 bool b2[N2] = {true, false, true, true, 28 false, false, true, true}; 29 std::valarray<int> v1(a1, N1); 30 const std::valarray<int> v2(a2, N2); 31 std::valarray<bool> vb1(b1, N1); 32 std::valarray<bool> vb2(b2, N2); 33 v1[vb1] = v2[vb2]; 34 assert(v1.size() == 16); 35 assert(v1[ 0] == -1); 36 assert(v1[ 1] == 1); 37 assert(v1[ 2] == 2); 38 assert(v1[ 3] == -3); 39 assert(v1[ 4] == -4); 40 assert(v1[ 5] == 5); 41 assert(v1[ 6] == 6); 42 assert(v1[ 7] == -7); 43 assert(v1[ 8] == 8); 44 assert(v1[ 9] == 9); 45 assert(v1[10] == 10); 46 assert(v1[11] == -8); 47 assert(v1[12] == 12); 48 assert(v1[13] == 13); 49 assert(v1[14] == 14); 50 assert(v1[15] == 15); 51 } 52 // Test return value of assignment 53 { 54 int a1[] = {0, 1, 2}; 55 int a2[] = {3, 4, 5}; 56 bool b1[] = {true, false, true}; 57 std::valarray<int> v1(a1, 3); 58 std::valarray<int> v2(a2, 3); 59 std::valarray<bool> const vb1(b1, 3); 60 std::mask_array<int> m1 = v1[vb1]; 61 std::mask_array<int> const m2 = v2[vb1]; 62 std::mask_array<int> const & r = (m1 = m2); 63 assert(&r == &m1); 64 } 65 66 return 0; 67 } 68