slice_array.pass.cpp 870 B

12345678910111213141516171819202122232425262728293031
  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(const slice_array<value_type>& sa);
  11. #include <valarray>
  12. #include <cassert>
  13. int main(int, char**)
  14. {
  15. int a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
  16. std::valarray<int> v1(a, sizeof(a)/sizeof(a[0]));
  17. std::valarray<int> v(v1[std::slice(1, 5, 3)]);
  18. assert(v.size() == 5);
  19. assert(v[0] == 1);
  20. assert(v[1] == 4);
  21. assert(v[2] == 7);
  22. assert(v[3] == 10);
  23. assert(v[4] == 13);
  24. return 0;
  25. }