We will start our journey with an introduction to the range-v3 library where you will learn about its main pillar - views - and how they relate to the functional programming notions of higher-order functions, composition and on-demand evaluation. We will be working with an online compiler.
60 little drills We will practise on short examples and learn to recognise situations in which to employ specific views. We will generate, transform, zip, accumulate and filter ranges. We will discover some remarkable uses
of one-to-many and many-to-one transformations such as chunk, slide, join and concatenate. Finally, we will address input, output and range comprehensions.
39 practical examples This book stands out for its practicality. You will find here a solid collection of 14 shorter examples, such as Hamming distance, Approximation of Pi, Meeting overlaps and 17 full-page examples, such as Fizz Buzz, Luhn algorithm, CamelCase to snake_case. These are followed by 3 longer advanced examples that handle input, custom objects and std::optional. To top it off, there are 5 examples of range comprehensions. See the full list of examples in the Table Of Contents. All the examples are complemented by visual cues to help you spot patterns and aid your learning process.
25 exercises with solutions You will practice what you learned on a series of exercises. We will be generating unusual sequences, narcissistic numbers and determining probabilities. We will be solving geometric problems and discovering some interesting uses of grouping. You won't be on your own, since we provided the source code of the solutions with basic commentary.
72 views A great part of this section is dedicated to views and their common uses. Thanks to this, you will be able to experiment with less frequently used views of the range-v3 library and perhaps come up with your very own patterns. In addition, you will find here an essential selection of range algorithms, iterators and accessors.
5 quizzers, 25 multiple choice questions The companion website contains quizzers, i.e. longer interactive exercises that let you practice Range-v3 and challenge you on the following topics:
Each quizzer consists of 5 multiple-choice questions related to the example and a little exercise to consolidate your knowledge.
The format readers like
Last update: 04 Dec 2023
Distribution of readers by continents
Last update: 04 Dec 2023
Questions you might have
What is the format and contents of this book?
The print book has a small compact A5 format, i.e. 148 x 210 mm or 5.8 x 8.3 inches and consists of 80 full color pages on satin-coated paper. There are five sections - Basics, Drill, Example guide, Practice and Quick reference. Visual cues, such as icons and colors, are used to help you identify and remember commonly occuring functional programming patterns. The book has a modern design, in coherence with the philosophy of modern C++. The book comes with the full source code of the examples and exercises published on the companion website.
Why isn't this a book on Ranges in C+20/23?
None of the C++23 compilers yet fully support all the essential functional programming notions implemented in range-v3. While GCC trunk already supports zipping, striding and sliding it lacks the ability to convert a view to an STL container. Additionally, some mission critical views from range-v3 such as views::cycle, views::concatenate, views::partial_sum, views::exclusive_scan and views::generate will only be implemented in C++26!
What is new in the 3rd edition of this book?
We have added 8 more pages in total 12 new examples with a specific focus on views::partial_sum, views::exclusive_scan and on non-uniform grouping or selection. Among the highlights are the Least common multiple, Meeting overlaps, Decimal to binary, Runsums, Rail fence cipher, Non-uniform chunks, Convert seconds to compound duration and Linear Convolution 1D. We also added 5 more exercises, among them Morse numerals, de Bruijn sequence and a cryptarithm.
Is this an official Range-v3 manual?
This book employs the range-v3 library to present practical examples, as such, it's not a substitute for an official documentation. Notwithstanding that, the book contains a Quick reference guide that covers common uses of 70 views currently implemented in the range-v3 library. Changes do appear on a regular basis, hence we recommend to consult the github account of range-v3, the website of Eric Niebler or Stackoverflow range-v3 topics.
Can I benefit from this book if I don't know C++?
Yes. The high-level notions presented in this book can be applied to other programming languages. The book has been read through and understood well by a non C++ developer. A word of caution, though. If you plan to proceed with C++, beware of the notion of undefined behavior. The book shows, that it's not difficult to run into dangling references if the idea behind views isn't well understood.
Will I learn about monads in this book?
Not at this point. C++ doesn't currently provide much support for monads. As far as side effects are concerned, we currently use std::optional to handle absence of a meaningful value, e.g. an unsuccessful search or a failed conversion.
Are the examples presented in this book optimised for speed?
In C++ we normally care about performance, but it's too early for optimizations. The aim is to develop high-level thinking, premature optimization would obscure the intent. Commonly used patterns will be eventually optimised by compilers.
Do I need to understand C++ Concepts to follow this book?
The focus of this book is on practical examples and high-level API, as a result C++ Concepts aren't part of this book. Nevertheless, you will occassionally find examples, where your views won't compose, as they differ in the constraints they place on the underlying range algorithms, in other words, they differ in Concepts (C++20). To take care of such cases, in this book, we resorted to materialization, i.e. an intermediate conversion to an STL container.
Is this book available on Amazon?
This is a small series and currently there aren't any plans to market it through large online resellers such as Amazon.
I ordered the PDF, can I still get the Print Book?
If you already own the PDF and would like to order the Print Book, send us an email with your order reference number. You will get a one-time link using which you can order the Print Book.
Why do I pay a premium for an A5 book?
The main goal of this manual is to save your time. Having it on your side, you'll quickly recoup your initial investment. The book delivers results instantly and saves you months of studying thanks to its comprehensive design. On top of that you'll get access to the companion website with quizzers that will help you effortlessly consolidate your knowledge.
Do you offer a Money Back Guarantee?
Yes, of course. If for any reason you’re not satisfied with the value of the book, simply email email@example.com during your first 30 days and your money will be refunded, no questions asked.
Information on orders / shipping
The shipping is included. Your book will be shipped in a protective B5 cardboard envelope via the Swiss Post International ECONOMY mail. Allow approximately
- 1 - 2 days for Switzerland
- 7 - 10 days for European countries
- 7 - 14 days for the US
- 10 - 20 days for the rest of the world
Attention: Exceptionally some countries (such as India) might levy an import tax on the physical part of the consignment.
Get in touch via email before making the following orders
- If you wish to own three or more items.
- If you are a VAT registered business / institution registered in the EU, i.e. eligible for the deduction of the national VAT rate for digital products under the reverse charge rule.
- If you already own a PDF and decided that you would also like the Print book.
Do you need help or more information?
Reach out at firstname.lastname@example.org for any questions you might have.
Thank you for your time and consideration!
Let's get things moving
Do you like C++ but miss the possibility to express ideas in a succinct manner without going into the details of the control flow?
Functional programming is coming to C++
Take the opportunity to discover functional programming principles with this innovative manual. Accompanied by visual cues, it lets you practise frequent functional techniques using the C++ Range-v3 library. In mere 80 pages you are guaranteed to gain fresh insights and develop a new train of thought directly applicable in C++23 Ranges.
Straight to the point
You won't need any setup. We will work with an online compiler on short and practical one-page examples.
Plenty of practice
The manual contains 60 little drills, 39 fully-elaborated examples, 25 exercises with solutions, 5 online quizzes and a quick reference.
The manual will challenge you to think in terms of logic, rather than in terms of control flow.
What is Range-v3?
The C++ Range-v3 library, authored by Eric Niebler and Casey Carter, is the predecessor of C++20/23 Ranges. The library brings C++ to a whole new level, introducing a simpler algorithmic API, composition and on-demand evaluation. This will allow you to write code that is easier to reason about, test and parallelize.