value_size.pass.cpp 1.0 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(const value_type& x, size_t n);
  11. #include <valarray>
  12. #include <cassert>
  13. int main(int, char**)
  14. {
  15. {
  16. std::valarray<int> v(5, 100);
  17. assert(v.size() == 100);
  18. for (int i = 0; i < 100; ++i)
  19. assert(v[i] == 5);
  20. }
  21. {
  22. std::valarray<double> v(2.5, 100);
  23. assert(v.size() == 100);
  24. for (int i = 0; i < 100; ++i)
  25. assert(v[i] == 2.5);
  26. }
  27. {
  28. std::valarray<std::valarray<double> > v(std::valarray<double>(10), 100);
  29. assert(v.size() == 100);
  30. for (int i = 0; i < 100; ++i)
  31. assert(v[i].size() == 10);
  32. }
  33. return 0;
  34. }