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 | |
9 | // <vector> |
10 | // vector<bool> |
11 | |
12 | // std::find with vector<bool>::iterator |
13 | |
14 | // https://llvm.org/PR16816 |
15 | |
16 | #include <vector> |
17 | #include <algorithm> |
18 | #include <cassert> |
19 | #include <cstddef> |
20 | |
21 | #include "test_macros.h" |
22 | |
23 | TEST_CONSTEXPR_CXX20 bool tests() |
24 | { |
25 | { |
26 | for (unsigned i = 1; i < 256; ++i) |
27 | { |
28 | std::vector<bool> b(i,true); |
29 | std::vector<bool>::iterator j = std::find(b.begin()+1, b.end(), false); |
30 | assert(static_cast<std::size_t>(j-b.begin()) == i); |
31 | assert(b.end() == j); |
32 | } |
33 | } |
34 | { |
35 | for (unsigned i = 1; i < 256; ++i) |
36 | { |
37 | std::vector<bool> b(i,false); |
38 | std::vector<bool>::iterator j = std::find(b.begin()+1, b.end(), true); |
39 | assert(static_cast<std::size_t>(j-b.begin()) == i); |
40 | assert(b.end() == j); |
41 | } |
42 | } |
43 | |
44 | return true; |
45 | } |
46 | |
47 | int main(int, char**) |
48 | { |
49 | tests(); |
50 | #if TEST_STD_VER > 17 |
51 | static_assert(tests()); |
52 | #endif |
53 | return 0; |
54 | } |
55 | |