brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.2 KiB · 26871f3 Raw
47 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 slice_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, 5, 6, 7, 8, 9};22  const unsigned N = sizeof(input) / sizeof(input[0]);23 24  std::valarray<unsigned> array(input, N);25 26  {27    std::slice_array<unsigned> result = array[std::slice(0, N, 1)];28    for (unsigned i = 0; i < N; ++i)29      assert(result.__get(i) == i);30  }31 32  {33    std::slice_array<unsigned> result = array[std::slice(3, 2, 2)];34    assert(result.__get(0) == 3);35    assert(result.__get(1) == 5);36  }37 38  {39    std::slice_array<unsigned> result = array[std::slice(1, 3, 4)];40    assert(result.__get(0) == 1);41    assert(result.__get(1) == 5);42    assert(result.__get(2) == 9);43  }44 45  return 0;46}47