“Generic Programming 2.0 with Concepts and Ranges” is a two-day training course with programming exercises taught by Christopher Di Bella. It is offered at the Meydenbauer Conference Center from 9AM to 5PM on Saturday and Sunday, September 29th and 30th, 2018 (immediately after the conference). Lunch is included.
Templates are a powerful tool that helps your code become expressive and robust, but making clear, concise, and correct generic interfaces can be a challenge.
Concepts — which have been over twenty years in the making — are a refinement over templates, allowing you to constrain your types to more specific interfaces; thereby almost completely eliminating the need for SFINAE. To paraphrase a committee member, concepts are not immediately useful without library support. This is where Ranges come in: the new Ranges library is a first step toward a new C++ standard library, that provides Standard concepts for you to use out of the box, more expressive algorithms (that better diagnose incorrect usage), and even more expressive ways to compose your operations.
Writing effective, general-purpose concepts for your domain is a skill that takes time to learn. We’ll spend some time initially exploring how to take advantage of the new library features and how to adapt your existing code to take advantage of their availability. We’ll then focus on showing you how to design and express concepts, so that you can refine your libraries and programs as clearer, more usable expressions of intent.
This course assumes familiarity with the following:
- C++14 core language features
- Templates and generic programming
Familiarity with any of the following is advantageous, but not completely essential:
- C++17 core language features
- 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.
The first day is dedicated to looking at the problems C++ programmers face when writing generic code using modern C++, and how we can leverage the Concepts TS to address these problems. By analysing hand-written algorithms from open-source projects — and understanding how to transform them into robust, generic data structures and algorithms that work for type genera (concepts) — we’ll explore why the Concepts TS isn’t immediately useful without the Ranges TS, and how the Ranges library can provide you with more composable, readable descriptions of your intent. Time will be set aside for you to practice using the Concepts TS and Ranges TS.
Day two will focus on modeling a real-world concept. Not everything deserves to be a concept: the C++ Standards Committee advises that we model concepts to reason about the meaning of your code, rather than getting your code to compile. This is not an easy skill to learn: a ‘good’ concept needs well-thought-out design requirements, and may need to have mathematical modeling. We will spend sufficient time talking about when we should write such concepts, the requirements that they need, and how to draw upon abstract algebra and logic to prove that our concept describes the constraint that we actually desire. It isn’t always possible to write a ‘good’ concept: sometimes we may find ourselves writing ‘dirty’ concepts to get the job done (concepts that reason about syntax only), so we’ll cover how to approach writing ‘dirty’ concepts. Finally, testing that concepts actually constrain types that model the concept is very important, so we’ll spend some time discussing how to test our own concepts.
- Course aim
- This course aims to develop students’ skills and understanding for modeling their interfaces’ type requirements.
|Students will develop
|1. knowledge and understanding about why concepts are necessary for constraining generic interfaces
|2. knowledge and understanding about why implementing concepts is a non-trivial task
|3. knowledge and understanding of the rationale and mathematics behind the concepts prescribed by the Ranges TS
|4. skills in using constraints to specify requirements for generic code
|5. skills in using Standard concepts to model requirements
|6. skills in using Ranges TS to simplify (and generify) handwritten algorithms
|7. skills in refining Ranges TS concepts
|8. skills in writing non-Standard concepts
|9. skills in writing tests for concept-checked code
- Assessment There will be no formal assessments such as exams or assignments in this course. The course will have exercises that students will be given time to solve on both days that students can use to gauge how well they are following along with the material being taught. All exercises will have solutions that will be released a few days after the course has concluded.
Christopher Di Bella is a Staff Software Engineer for Codeplay’s ComputeCpp Runtime Technology. He is a strong proponent for having the Concepts TS and the Ranges TS in C++20. Chris spends his days working on ComputeCpp, Codeplay’s implementation of SYCL; the Khronos implementation for the Parallel STL (using SYCL); and researching Parallel Ranges, which is an attempt to bring the aforementioned Ranges TS together with the parallel algorithms. He was previously a software developer for Nasdaq, and a tutor for UNSW Australia’s COMP6771 Advanced C++ Programming course in Sydney, Australia. In his spare time, Chris enjoys snowboarding, playing games, and watching films.