const_access.pass.cpp 806 B

1234567891011121314151617181920212223242526272829303132
  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. // const value_type& operator[](size_t i) const;
  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. const std::valarray<T> v(a, N);
  20. for (unsigned i = 0; i < N; ++i)
  21. {
  22. assert(v[i] == a[i]);
  23. }
  24. }
  25. return 0;
  26. }