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 valarray; 12 13 // valarray operator[](slice s) const; 14 15 #include <valarray> 16 #include <cassert> 17 18 int main(int, char**) 19 { 20 { 21 int a1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; 22 const std::valarray<int> v1(a1, sizeof(a1)/sizeof(a1[0])); 23 std::valarray<int> v2 = v1[std::slice(1, 5, 3)]; 24 assert(v2.size() == 5); 25 assert(v2[0] == 1); 26 assert(v2[1] == 4); 27 assert(v2[2] == 7); 28 assert(v2[3] == 10); 29 assert(v2[4] == 13); 30 } 31 { 32 int a1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; 33 const std::valarray<int> v1(a1, sizeof(a1)/sizeof(a1[0])); 34 std::valarray<int> v2 = (v1 + 0)[std::slice(0, 2, 3)]; 35 assert(v2.size() == 2); 36 assert(v2[0] == 0); 37 assert(v2[1] == 3); 38 } 39 return 0; 40 } 41