access.pass.cpp 859 B

12345678910111213141516171819202122232425262728293031323334
  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. // value_type& operator[](size_t i);
  11. #include <valarray>
  12. #include <cassert>
  13. int main(int, char**)
  14. {
  15. {
  16. typedef int T;
  17. T a[] = {5, 4, 3, 2, 1};
  18. const unsigned N = sizeof(a)/sizeof(a[0]);
  19. std::valarray<T> v(a, N);
  20. for (unsigned i = 0; i < N; ++i)
  21. {
  22. assert(v[i] == a[i]);
  23. v[i] = i;
  24. assert(v[i] == static_cast<int>(i));
  25. }
  26. }
  27. return 0;
  28. }