mask_array.pass.cpp 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  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 mask_array<value_type>& ma);
  11. #include <valarray>
  12. #include <cassert>
  13. int main(int, char**)
  14. {
  15. int a1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
  16. const std::size_t N1 = sizeof(a1)/sizeof(a1[0]);
  17. bool b[N1] = {true, false, false, true, true, false,
  18. false, true, false, false, false, true};
  19. std::valarray<int> v1(a1, N1);
  20. std::valarray<bool> vb(b, N1);
  21. std::valarray<int> v2(v1[vb]);
  22. assert(v2.size() == 5);
  23. assert(v2[ 0] == 0);
  24. assert(v2[ 1] == 3);
  25. assert(v2[ 2] == 4);
  26. assert(v2[ 3] == 7);
  27. assert(v2[ 4] == 11);
  28. return 0;
  29. }