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 useful one-to-many and one-to-many transformations such as group, chunk, slide, join and concatenate. Finally, we will get down to input, output and range comprehensions.
27 practical examples This is a solid collection of 8 shorter examples, such as Hamming distance, Approximation of Pi and 11 full-page examples, such as Fizz Buzz and Luhn algorithm. These are followed by 3 longer advanced examples that handle input, user-defined 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.
20 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.
70 views, 22 actions 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.
When looking for primes, what is the most reasonable range of candidate factors that we have to investigate for a particular number n?
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 the groundbreaking paradigm with this innovative manual. Accompanied by visual cues, it lets you practise functional programming techniques using the C++ Range-v3 library. In mere 72 pages you are guaranteed to gain fresh insights and develop a new train of thought.
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, 27 fully-elaborated examples, 20 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 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.
What is inside this book?
The format readers like
Last update: 15 Aug 2022
Distribution of readers by continents
Last update: 15 Aug 2022
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 72 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?
As of now, range-v3 is contains many convenience views that weren't incorporated into C++20. Zipping was omitted from C++20 due to issues with proxy iterators and partial specializations (std::vector<bool>). Furthermore, some very useful views that can take care of cyclicity, grouping, striding, sliding etc. aren't part of C++20.
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++20 Concepts to follow this book?
The focus of this book is on practical examples and high-level API, as a result C++20 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 firstname.lastname@example.org 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 email@example.com for any questions you might have.
Thank you for your time and consideration!