access.pass.cpp 799 B

123456789101112131415161718192021222324252627282930313233
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is dual licensed under the MIT and the University of Illinois Open
  6. // Source Licenses. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. // <valarray>
  10. // template<class T> class valarray;
  11. // value_type& operator[](size_t i);
  12. #include <valarray>
  13. #include <cassert>
  14. int main()
  15. {
  16. {
  17. typedef int T;
  18. T a[] = {5, 4, 3, 2, 1};
  19. const unsigned N = sizeof(a)/sizeof(a[0]);
  20. std::valarray<T> v(a, N);
  21. for (int i = 0; i < N; ++i)
  22. {
  23. assert(v[i] == a[i]);
  24. v[i] = i;
  25. assert(v[i] == i);
  26. }
  27. }
  28. }