brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.5 KiB · 2a1842f Raw
53 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 gslice_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::gslice_array<unsigned> result =28        array[std::gslice(0, std::valarray<std::size_t>(N, 1), std::valarray<std::size_t>(1, 1))];29    for (unsigned i = 0; i < N; ++i)30      assert(result.__get(i) == i);31  }32 33  {34    std::valarray<std::size_t> sizes(2);35    sizes[0] = 2;36    sizes[1] = 3;37 38    std::valarray<std::size_t> strides(2);39    strides[0] = 6;40    strides[1] = 1;41 42    std::gslice_array<unsigned> result = array[std::gslice(1, sizes, strides)];43    assert(result.__get(0) == input[1 + 0 * 6 + 0 * 1]);44    assert(result.__get(1) == input[1 + 0 * 6 + 1 * 1]);45    assert(result.__get(2) == input[1 + 0 * 6 + 2 * 1]);46 47    assert(result.__get(3) == input[1 + 1 * 6 + 0 * 1]);48    assert(result.__get(4) == input[1 + 1 * 6 + 1 * 1]);49    assert(result.__get(5) == input[1 + 1 * 6 + 2 * 1]);50  }51  return 0;52}53