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