@@ -10,16 +10,12 @@ module;
10
10
export module containers.algorithms.binary_search;
11
11
12
12
import containers.algorithms.partition;
13
- import containers.array;
14
13
import containers.begin_end;
15
14
import containers.range;
16
15
import containers.range_view;
17
16
18
- import bounded;
19
17
import std_module;
20
18
21
- using namespace bounded ::literal;
22
-
23
19
namespace containers {
24
20
25
21
struct lower_bound_t {
@@ -71,101 +67,3 @@ struct binary_search_t {
71
67
export constexpr auto binary_search = binary_search_t ();
72
68
73
69
} // namespace containers
74
-
75
- constexpr auto zero = containers::array<int , 0_bi>{};
76
- constexpr auto one = containers::array{1 };
77
- constexpr auto two = containers::array{1 , 2 };
78
- constexpr auto three = containers::array{1 , 2 , 3 };
79
- constexpr auto two_duplicates = containers::array{1 , 1 };
80
- constexpr auto three_duplicates = containers::array{1 , 1 , 1 };
81
- constexpr auto three_two_duplicates_first = containers::array{1 , 1 , 2 };
82
- constexpr auto three_two_duplicates_last = containers::array{1 , 2 , 2 };
83
-
84
- static_assert (containers::lower_bound(zero, 0 ) == end(zero));
85
- static_assert (containers::upper_bound(zero, 0 ) == end(zero));
86
- static_assert (!containers::binary_search(zero, 0 ));
87
-
88
- static_assert (containers::lower_bound(one, 0 ) == begin(one));
89
- static_assert (containers::lower_bound(one, 1 ) == begin(one));
90
- static_assert (containers::lower_bound(one, 2 ) == end(one));
91
- static_assert (containers::upper_bound(one, 0 ) == begin(one));
92
- static_assert (containers::upper_bound(one, 1 ) == end(one));
93
- static_assert (containers::upper_bound(one, 2 ) == end(one));
94
- static_assert (!containers::binary_search(one, 0 ));
95
- static_assert (containers::binary_search(one, 1 ));
96
- static_assert (!containers::binary_search(one, 2 ));
97
-
98
- static_assert (containers::lower_bound(two, 0 ) == begin(two) + 0_bi);
99
- static_assert (containers::lower_bound(two, 1 ) == begin(two) + 0_bi);
100
- static_assert (containers::lower_bound(two, 2 ) == begin(two) + 1_bi);
101
- static_assert (containers::lower_bound(two, 3 ) == end(two));
102
- static_assert (containers::upper_bound(two, 0 ) == begin(two) + 0_bi);
103
- static_assert (containers::upper_bound(two, 1 ) == begin(two) + 1_bi);
104
- static_assert (containers::upper_bound(two, 2 ) == begin(two) + 2_bi);
105
- static_assert (containers::upper_bound(two, 3 ) == end(two));
106
- static_assert (!containers::binary_search(two, 0 ));
107
- static_assert (containers::binary_search(two, 1 ));
108
- static_assert (containers::binary_search(two, 2 ));
109
- static_assert (!containers::binary_search(two, 3 ));
110
-
111
- static_assert (containers::lower_bound(three, 0 ) == begin(three) + 0_bi);
112
- static_assert (containers::lower_bound(three, 1 ) == begin(three) + 0_bi);
113
- static_assert (containers::lower_bound(three, 2 ) == begin(three) + 1_bi);
114
- static_assert (containers::lower_bound(three, 3 ) == begin(three) + 2_bi);
115
- static_assert (containers::lower_bound(three, 4 ) == end(three));
116
- static_assert (containers::upper_bound(three, 0 ) == begin(three) + 0_bi);
117
- static_assert (containers::upper_bound(three, 1 ) == begin(three) + 1_bi);
118
- static_assert (containers::upper_bound(three, 2 ) == begin(three) + 2_bi);
119
- static_assert (containers::upper_bound(three, 3 ) == begin(three) + 3_bi);
120
- static_assert (containers::upper_bound(three, 4 ) == end(three));
121
- static_assert (!containers::binary_search(three, 0 ));
122
- static_assert (containers::binary_search(three, 1 ));
123
- static_assert (containers::binary_search(three, 2 ));
124
- static_assert (containers::binary_search(three, 3 ));
125
- static_assert (!containers::binary_search(three, 4 ));
126
-
127
- static_assert (containers::lower_bound(two_duplicates, 0 ) == begin(two_duplicates) + 0_bi);
128
- static_assert (containers::lower_bound(two_duplicates, 1 ) == begin(two_duplicates) + 0_bi);
129
- static_assert (containers::lower_bound(two_duplicates, 2 ) == end(two_duplicates));
130
- static_assert (containers::upper_bound(two_duplicates, 0 ) == begin(two_duplicates) + 0_bi);
131
- static_assert (containers::upper_bound(two_duplicates, 1 ) == end(two_duplicates));
132
- static_assert (containers::upper_bound(two_duplicates, 2 ) == end(two_duplicates));
133
- static_assert (!containers::binary_search(two_duplicates, 0 ));
134
- static_assert (containers::binary_search(two_duplicates, 1 ));
135
- static_assert (!containers::binary_search(two_duplicates, 2 ));
136
-
137
- static_assert (containers::lower_bound(three_duplicates, 0 ) == begin(three_duplicates) + 0_bi);
138
- static_assert (containers::lower_bound(three_duplicates, 1 ) == begin(three_duplicates) + 0_bi);
139
- static_assert (containers::lower_bound(three_duplicates, 2 ) == end(three_duplicates));
140
- static_assert (containers::upper_bound(three_duplicates, 0 ) == begin(three_duplicates) + 0_bi);
141
- static_assert (containers::upper_bound(three_duplicates, 1 ) == end(three_duplicates));
142
- static_assert (containers::upper_bound(three_duplicates, 2 ) == end(three_duplicates));
143
- static_assert (!containers::binary_search(three_duplicates, 0 ));
144
- static_assert (containers::binary_search(three_duplicates, 1 ));
145
- static_assert (!containers::binary_search(three_duplicates, 2 ));
146
-
147
- static_assert (containers::lower_bound(three_two_duplicates_first, 0 ) == begin(three_two_duplicates_first) + 0_bi);
148
- static_assert (containers::lower_bound(three_two_duplicates_first, 1 ) == begin(three_two_duplicates_first) + 0_bi);
149
- static_assert (containers::lower_bound(three_two_duplicates_first, 2 ) == begin(three_two_duplicates_first) + 2_bi);
150
- static_assert (containers::lower_bound(three_two_duplicates_first, 3 ) == end(three_two_duplicates_first));
151
- static_assert (containers::upper_bound(three_two_duplicates_first, 0 ) == begin(three_two_duplicates_first) + 0_bi);
152
- static_assert (containers::upper_bound(three_two_duplicates_first, 1 ) == begin(three_two_duplicates_first) + 2_bi);
153
- static_assert (containers::upper_bound(three_two_duplicates_first, 2 ) == begin(three_two_duplicates_first) + 3_bi);
154
- static_assert (containers::upper_bound(three_two_duplicates_first, 3 ) == end(three_two_duplicates_first));
155
- static_assert (!containers::binary_search(three_two_duplicates_first, 0 ));
156
- static_assert (containers::binary_search(three_two_duplicates_first, 1 ));
157
- static_assert (containers::binary_search(three_two_duplicates_first, 2 ));
158
- static_assert (!containers::binary_search(three_two_duplicates_first, 3 ));
159
-
160
- static_assert (containers::lower_bound(three_two_duplicates_last, 0 ) == begin(three_two_duplicates_last) + 0_bi);
161
- static_assert (containers::lower_bound(three_two_duplicates_last, 1 ) == begin(three_two_duplicates_last) + 0_bi);
162
- static_assert (containers::lower_bound(three_two_duplicates_last, 2 ) == begin(three_two_duplicates_last) + 1_bi);
163
- static_assert (containers::lower_bound(three_two_duplicates_last, 3 ) == end(three_two_duplicates_last));
164
- static_assert (containers::upper_bound(three_two_duplicates_last, 0 ) == begin(three_two_duplicates_last) + 0_bi);
165
- static_assert (containers::upper_bound(three_two_duplicates_last, 1 ) == begin(three_two_duplicates_last) + 1_bi);
166
- static_assert (containers::upper_bound(three_two_duplicates_last, 2 ) == begin(three_two_duplicates_last) + 3_bi);
167
- static_assert (containers::upper_bound(three_two_duplicates_last, 3 ) == end(three_two_duplicates_last));
168
- static_assert (!containers::binary_search(three_two_duplicates_last, 0 ));
169
- static_assert (containers::binary_search(three_two_duplicates_last, 1 ));
170
- static_assert (containers::binary_search(three_two_duplicates_last, 2 ));
171
- static_assert (!containers::binary_search(three_two_duplicates_last, 3 ));
0 commit comments