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 // T __get(size_t i);
14
15 #include <valarray>
16 #include <cassert>
17
18 #include "test_macros.h"
19
main(int,char **)20 int main(int, char**) {
21 unsigned input[] = {0, 1, 2, 3, 4};
22 const unsigned N = sizeof(input) / sizeof(input[0]);
23
24 std::valarray<unsigned> array(input, N);
25
26 {
27 std::mask_array<unsigned> result = array[std::valarray<bool>(true, N)];
28 for (unsigned i = 0; i < N; ++i)
29 assert(result.__get(i) == i);
30 }
31
32 {
33 std::valarray<bool> mask(false, N);
34 mask[1] = true;
35 mask[3] = true;
36 std::mask_array<unsigned> result = array[mask];
37 assert(result.__get(0) == 1);
38 assert(result.__get(1) == 3);
39 }
40
41 {
42 std::valarray<bool> mask(false, N);
43 mask[0] = true;
44 mask[4] = true;
45 std::mask_array<unsigned> result = array[mask];
46 assert(result.__get(0) == 0);
47 assert(result.__get(1) == 4);
48 }
49
50 return 0;
51 }
52