@@ -154,17 +154,20 @@ TEST(find_end, ExampleOne) {
154154 EXPECT_EQ (last_sequence_iterator - v.cbegin (), 8 ); // Iterator begins at last sub-sequence.
155155}
156156
157+ // Note that find_first_of() is looking for ANY of the elements
158+ // in the search range. This is different from search(), which is looking
159+ // for the entire sequence.
157160TEST (find_first_of, ExampleOne) {
158161 const std::vector<char > v{' 1' , ' 2' , ' w' , ' o' , ' r' , ' d' , ' 3' , ' 3' };
159- const std::vector<char > sequence = {' w' , ' o ' , ' r' , ' d' };
162+ const std::vector<char > sequence = {' w' , ' r' , ' d' };
160163 const auto iterator = std::find_first_of (v.cbegin (), v.cend (), sequence.cbegin (), sequence.cend ());
161164 EXPECT_EQ (*iterator, ' w' );
162165 EXPECT_EQ (iterator - v.cbegin (), 2 );
163166}
164167
165168TEST (find_first_of, ExampleTwoWithPredicate) {
166169 const std::vector<char > v{' w' , ' o' , ' r' , ' d' , ' 1' , ' W' , ' O' , ' R' , ' D' , ' 3' , ' 3' };
167- const std::vector<char > sequence = {' w' , ' o ' , ' r' , ' d' };
170+ const std::vector<char > sequence = {' w' , ' r' , ' d' };
168171 const auto isCapitalized = [](char c1, char c2)->bool {
169172 return std::tolower (c1) == std::tolower (c2) && c1 >= ' A' && c1 <= ' Z' ;
170173 };
@@ -192,12 +195,45 @@ TEST(adjacent_find, ExampleTwoWithPredicate) {
192195 EXPECT_EQ (iterator - v.cbegin (), 3 );
193196}
194197
195- TEST (search, ExampleOne) {}
198+ // Note that there exists a search_n() as well,
199+ // that takes in the number of elements to search.
200+ TEST (search, ExampleOne) {
201+ // This is going to find the first sub-sequence inside a container,
202+ // and return an iterator to it.
203+ const std::vector<int > v{1 ,2 ,3 ,4 ,1 ,2 ,3 ,4 ,1 ,2 ,3 ,4 };
204+ const std::vector<int > sequence{1 ,2 ,3 ,4 };
205+ const auto sequence_iterator = std::search (v.cbegin (), v.cend (), sequence.cbegin (), sequence.cend ());
206+ EXPECT_EQ (*sequence_iterator, 1 );
207+ EXPECT_EQ (sequence_iterator - v.cbegin (), 0 ); // Iterator begins at last sub-sequence.
208+ }
196209
197- TEST (search_n, ExampleOne) {}
210+ TEST (search, ExampleTwoWithPredicate) {
211+ const std::vector<char > v{' w' , ' o' , ' r' , ' d' , ' 1' , ' W' , ' O' , ' R' , ' D' , ' 3' , ' 3' };
212+ const std::vector<char > sequence = {' w' , ' o' , ' r' , ' d' };
213+ const auto isCapitalized = [](char c1, char c2)->bool {
214+ return std::tolower (c1) == std::tolower (c2) && c1 >= ' A' && c1 <= ' Z' ;
215+ };
216+ const auto iterator = std::search (v.cbegin (), v.cend (), sequence.cbegin (), sequence.cend (), isCapitalized);
217+ EXPECT_EQ (*iterator, ' W' );
218+ EXPECT_EQ (iterator - v.cbegin (), 5 );
219+ }
198220
199221// Modifying sequence operations.
200222
223+ // Note that copy_n() also exists that takes in another
224+ // parameter to copy only the first n elements.
225+ TEST (copy, ExampleOne) {
226+
227+ }
228+
229+ TEST (copy_if, ExampleOne) {
230+
231+ }
232+
233+ TEST (copy_backward, ExampleOne) {
234+
235+ }
236+
201237// Partitioning operations.
202238
203239// Sorting operations.
0 commit comments