Applied Modern C++: Generic Programming is a two-day training course with programming exercises taught by Christopher Di Bella. It is offered at the Gaylord Rockies from 9AM to 5PM on Saturday and Sunday, September 12th and 13th (immediately prior to the conference). Lunch is included.
Generic programming is so much more than using templates: it’s a whole programming paradigm, studying how to abstract algorithm bases, so they apply to varying data structures that share a common vocabulary. A properly designed interface leveraging generic programming imposes requirements on user syntax (constraints), semantic behaviour (axioms), and complexity guarantees. Collectively, we call these three sets of requirements concepts.
C++20 has language support for concepts, which is a huge win for the community. To paraphrase a standards committee member, concepts are not immediately useful without library support; C++20 also shipped with a ranges library. Ranges are a rejuvenated STL, redesigned from the ground up with C++20 concepts in mind. Part of the library includes families of concepts for you to use straight out of the box, while the rest focuses on algorithms and range adaptors (commonly called “views” or “ranges”), which allow you to design solutions that clearly describe your intentions and eliminate room for error
in your programs.
Generic programming —including both learning how to use the algorithmic facilities, and how to write general-purpose algorithms and concepts for your domain— is a learnt skill. In this class, you’ll learn how to:
- use and debug generic algorithms and range adaptors,
- design your own generic algorithms,
- design concepts that pin down your algorithms’ requirements, and
- design your own range adaptors
This course assumes familiarity with the following:
- C++17 core language features
- C++ standard library containers
Familiarity with any of the following is advantageous, but not completely essential:
- C++20 core language features
- other areas of the C++ Standard Library
- Reading technical papers such as C++ Standard proposals
Please ensure that you have installed and configured Docker as per the class installation instructions prior to attending the class.
Day 1: What is generic programming from a user’s perspective?
Day 1 focuses on using algorithms, ranges, and understanding concepts as they are applied to the former two. Half of the first day is spent learning how to solve problems using algorithms and range adaptors, as well as looking at how to debug range-based code when things go wrong. As concepts underpin a lot of what we’ll be using, some time will be set aside for looking at how concepts are used in C++20.
After understanding how to use these tools, we’ll begin to look at how we design generic algorithms and derive relevant concepts. We’ll spend a portion of this module studying algorithm patterns across different data structures, how we can abstract the salient elements from implementations concerning different data structures to establish a common vocabulary.
By the time Saturday is finished, you should be able to write solutions from scratch using algorithms and range adaptors, and take existing code that could use algorithms, and re-write them as such. When an algorithm isn’t readily at your fingertips, you’ll have the skills to write one yourself.
Day 2: What is generic programming from an implementer’s perspective?
Day 2 takes Christopher’s CppCon 2019 Main Session (parts one and two) talk to the next level, and gives you a hands-on lab for designing and implementing your own range adaptor. Unlike in the CppCon 2019 session, which needed to cater to a broader audience, we’ll dive much deeper into the subject and address the missing material from that two-hour session.
Of course, it wouldn’t be a lab if there wasn’t a hands-on component, so you’ll have ample time to implement a range adaptor by yourself, ask questions, and learn what you’d need to do while waiting for your favourite range adaptor to hit standard C++.
Christopher Di Bella is a software engineer at Google. He is a strong proponent for generic programming in C++ and C++ education. When not geeking out over C++, he enjoys snowboarding, playing games, and watching films.