not.pass.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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<bool> operator!() const;
  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. std::valarray<bool> v2 = !v;
  22. assert(v2.size() == v.size());
  23. for (std::size_t i = 0; i < v2.size(); ++i)
  24. assert(v2[i] == !v[i]);
  25. }
  26. {
  27. typedef double T;
  28. T a[] = {1, 2.5, 3, 4.25, 5};
  29. const unsigned N = sizeof(a)/sizeof(a[0]);
  30. std::valarray<T> v(a, N);
  31. std::valarray<bool> v2 = !(v + v);
  32. assert(v2.size() == v.size());
  33. for (std::size_t i = 0; i < v2.size(); ++i)
  34. assert(v2[i] == !(2 * v[i]));
  35. }
  36. return 0;
  37. }