initializer_list.pass.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. // UNSUPPORTED: c++98, c++03
  9. // <valarray>
  10. // template<class T> class valarray;
  11. // valarray(initializer_list<value_type>);
  12. #include <valarray>
  13. #include <cassert>
  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 = {1, 2, 3, 4, 5};
  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, 3, 4, 5};
  28. const unsigned N = sizeof(a)/sizeof(a[0]);
  29. std::valarray<T> v = {1, 2, 3, 4, 5};
  30. assert(v.size() == N);
  31. for (unsigned i = 0; i < N; ++i)
  32. assert(v[i] == a[i]);
  33. }
  34. return 0;
  35. }