find.pass.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. // <vector>
  9. // vector<bool>
  10. // std::find with vector<bool>::iterator
  11. // https://bugs.llvm.org/show_bug.cgi?id=16816
  12. #include <vector>
  13. #include <algorithm>
  14. #include <cassert>
  15. #include <cstddef>
  16. #include "test_macros.h"
  17. int main(int, char**)
  18. {
  19. {
  20. for (unsigned i = 1; i < 256; ++i)
  21. {
  22. std::vector<bool> b(i,true);
  23. std::vector<bool>::iterator j = std::find(b.begin()+1, b.end(), false);
  24. assert(static_cast<std::size_t>(j-b.begin()) == i);
  25. assert(b.end() == j);
  26. }
  27. }
  28. {
  29. for (unsigned i = 1; i < 256; ++i)
  30. {
  31. std::vector<bool> b(i,false);
  32. std::vector<bool>::iterator j = std::find(b.begin()+1, b.end(), true);
  33. assert(static_cast<std::size_t>(j-b.begin()) == i);
  34. assert(b.end() == j);
  35. }
  36. }
  37. return 0;
  38. }