Book Image

Modern C++: Efficient and Scalable Application Development

By : Richard Grimes, Marius Bancila
Book Image

Modern C++: Efficient and Scalable Application Development

By: Richard Grimes, Marius Bancila

Overview of this book

C++ is one of the most widely used programming languages. It is fast, flexible, and used to solve many programming problems. This Learning Path gives you an in-depth and hands-on experience of working with C++, using the latest recipes and understanding most recent developments. You will explore C++ programming constructs by learning about language structures, functions, and classes, which will help you identify the execution flow through code. You will also understand the importance of the C++ standard library as well as memory allocation for writing better and faster programs. Modern C++: Efficient and Scalable Application Development deals with the challenges faced with advanced C++ programming. You will work through advanced topics such as multithreading, networking, concurrency, lambda expressions, and many more recipes. By the end of this Learning Path, you will have all the skills to become a master C++ programmer. This Learning Path includes content from the following Packt products: • Beginning C++ Programming by Richard Grimes • Modern C++ Programming Cookbook by Marius Bancila • The Modern C++ Challenge by Marius Bancila
Table of Contents (24 chapters)
Title Page
About Packt
Math Problems
Language Features
Strings and Regular Expressions
Streams and Filesystems
Date and Time
Algorithms and Data Structures


The Standard Library has an extensive collection of generic functions in the <algorithm> header file. By generic we mean that they access data via iterators without knowing what the iterators refer to and so it means that you can write generic code to work for any appropriate container. However, if you know the container type and that container has a member method to perform the same action, you should use the member.

Iteration of items

Many of the routines in <algorithm> will take ranges and iterate over those ranges performing some action. As the name suggests, the fill function will fill a container with a value. The function takes two iterators to specify the range and a value that will be placed into each position of the container:

    vector<int> vec; 
    fill(vec.begin(), vec.end(), 42);

Since the fill function will be called for a range, it means that you have to pass iterators to a container that already has values, and this is the reason...