pointer_size.pass.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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* p, size_t n);
  11. #include <valarray>
  12. #include <cassert>
  13. #include <cstddef>
  14. int main(int, char**)
  15. {
  16. {
  17. typedef int T;
  18. T a[] = {1, 2, 3, 4, 5};
  19. const unsigned N = sizeof(a)/sizeof(a[0]);
  20. std::valarray<T> v(a, N);
  21. assert(v.size() == N);
  22. for (unsigned i = 0; i < N; ++i)
  23. assert(v[i] == a[i]);
  24. }
  25. {
  26. typedef double T;
  27. T a[] = {1, 2.5, 3, 4.25, 5};
  28. const unsigned N = sizeof(a)/sizeof(a[0]);
  29. std::valarray<T> v(a, N);
  30. assert(v.size() == N);
  31. for (unsigned i = 0; i < N; ++i)
  32. assert(v[i] == a[i]);
  33. }
  34. {
  35. typedef std::valarray<double> T;
  36. T a[] = {T(1), T(2), T(3), T(4), T(5)};
  37. const unsigned N = sizeof(a)/sizeof(a[0]);
  38. std::valarray<T> v(a, N);
  39. assert(v.size() == N);
  40. for (unsigned i = 0; i < N; ++i)
  41. {
  42. assert(v[i].size() == a[i].size());
  43. for (std::size_t j = 0; j < v[i].size(); ++j)
  44. assert(v[i][j] == a[i][j]);
  45. }
  46. }
  47. return 0;
  48. }