From the course: C++ Templates and the STL
Unlock this course with a free trial
Join today to access over 22,600 courses taught by industry experts.
Modifying algorithms - C++ Tutorial
From the course: C++ Templates and the STL
Modifying algorithms
- The STL contains additional modifying algorithms that make changes to sequences. There are quite a few of these, so let's get started. Here I have a working copy of modify.cpp from Chapter six of the exercise files. The simplest of the modifying algorithms is the copy function. Copy makes a copy of the source range to the target, and so you give it a source range with begin and end and a target begin, and when I build and run our v1 is the prime numbers, our v2 is filled with zeros of the same size and then copy, copies v1 to v2. There's also a copy_n version, does the same thing but instead of the end iterator, you give it a number of items to copy. Let's say we're going to copy 15 of these items and you'll notice that it does exactly that. There's a copy_backward algorithm which does not do what you might think it does. This copies the elements back to front, but the result is in the original order. So, instead of a begin point for the second container, we give it an end point…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
-
(Locked)
About STL algorithms1m 42s
-
(Locked)
Testing conditions2m 36s
-
(Locked)
Searching and counting4m 38s
-
(Locked)
Replacing and removing4m 14s
-
(Locked)
Modifying algorithms5m 46s
-
(Locked)
Partitions2m 52s
-
(Locked)
Sorting3m 42s
-
(Locked)
Merging sequences2m 4s
-
(Locked)
Binary searches3m 57s
-
(Locked)
-