slice_const.pass.cpp 1.2 KB

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