55 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// <valarray>10 11// template<class T> class valarray;12 13// valarray operator[](const valarray<bool>& vb) const;14 15#include <valarray>16#include <cassert>17 18#include "test_macros.h"19 20 21int main(int, char**)22{23 {24 int a1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};25 const std::size_t N1 = sizeof(a1)/sizeof(a1[0]);26 bool b[N1] = {true, false, false, true, true, false,27 false, true, false, false, false, true};28 std::valarray<int> v1(a1, N1);29 std::valarray<bool> vb(b, N1);30 std::valarray<int> v2(v1[vb]);31 assert(v2.size() == 5);32 assert(v2[ 0] == 0);33 assert(v2[ 1] == 3);34 assert(v2[ 2] == 4);35 assert(v2[ 3] == 7);36 assert(v2[ 4] == 11);37 }38 {39 int a1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};40 const std::size_t N1 = sizeof(a1)/sizeof(a1[0]);41 bool b[N1] = {true, false, false, true, true, false,42 false, true, false, false, false, true};43 std::valarray<int> v1(a1, N1);44 std::valarray<bool> vb(b, N1);45 std::valarray<int> v2((v1 - 1)[vb]);46 assert(v2.size() == 5);47 assert(v2[ 0] == -1);48 assert(v2[ 1] == 2);49 assert(v2[ 2] == 3);50 assert(v2[ 3] == 6);51 assert(v2[ 4] == 10);52 }53 return 0;54}55