brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.2 KiB · 3c50c74 Raw
45 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 indirect_array;12 13// T __get(size_t i);14 15#include <valarray>16#include <cassert>17 18#include "test_macros.h"19 20int 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::indirect_array<unsigned> result = array[std::valarray<std::size_t>(std::size_t(0), std::size_t(N))];28    for (unsigned i = 0; i < N; ++i)29      assert(result.__get(i) == 0);30  }31 32  {33    std::valarray<std::size_t> indirect(std::size_t(0), std::size_t(3));34    indirect[0]                          = 4;35    indirect[1]                          = 1;36    indirect[2]                          = 3;37    std::indirect_array<unsigned> result = array[indirect];38    assert(result.__get(0) == 4);39    assert(result.__get(1) == 1);40    assert(result.__get(2) == 3);41  }42 43  return 0;44}45