Book Image

The C++ Standard Library - Second Edition

By : Rainer Grimm
Book Image

The C++ Standard Library - Second Edition

By: Rainer Grimm

Overview of this book

Standard template library enables programmers to speed up application development using the built-in data structures and algorithms in their codes. The C++ Standard Library is a comprehensive guide to the updated library of classes, algorithms, functions, iterators, and containers and serves as the best reference to the current C++ 17 standard. Starting with the introduction and history of the standard library, this book goes on to demonstrate how quickly you can manipulate various C++ template classes while writing your applications. You'll also learn in detail the four types of STL components. Then you'll discover the best methods to analyze or modify a string. You'll also learn how to make your application communicate with the outside world using input and output streams and how to use the non-owning string objects with regular strings. By the end of this book, you'll be able to take your programming skills to a higher level by leveraging the standard C++ libraries.
Table of Contents (19 chapters)
Free Chapter
1
Reader Testimonials
8
6. Adaptors for Containers
19
Index

Modifying Algorithms

C++ has many algorithms to modify elements and ranges.

Copy Elements and Ranges

You can copy ranges forward with std::copy, backward with std::copy_backward and conditionally with std::copy_if. If you want to copy n elements, you can use std::copy_n.

Copies the range:

OutIt copy(InpIt first, InpIt last, OutIt result)
FwdIt2 copy(ExePol pol, FwdIt first, FwdIt last, FowdIt2 result)

Copies n elements:

OutIt copy_n(InpIt first, Size n, OutIt result)
FwdIt2 copy_n(ExePol pol, FwdIt first, Size n, FwdIt2 result)

Copies the elements dependent on the predicate pre.

OutIt copy_if(InpIt first, InpIt last, OutIt result, UnPre pre)
FwdIt2 copy_if(ExePol pol, FwdIt first, FwdIt last, FwdIt2 result, UnPre pre)

Copies the range backward:

BiIt copy_backward(BiIt first, BiIt last, BiIt result)

The algorithms need input iterators and copy their elements to result. They return an end iterator to the destination range.

Copy elements and ranges
...