Seminar 1 is given as a quick introduction to basic C++,
actually prerequisites. If already familiar with C++11/14/17, you may
consider to skip seminar 1, but have a look at the material.
All the old lecture slides are available as pdfs for each seminar. There is also a rendering in HTML available with links to the topics covered here
Full size seminar slides are linked from each topic heading. [2x2] shows miniatures, 4 slides per page.
Also the two larger, complete code examples used for seminar 45 (String) and seminar 67 (P-E-M-C) are linked below.
Seminar plan for study period Vt1, week 39
Introduction and overview [Language overview; 2x2]
Introduction to the course. Overview C++.
Basic C++ (1) [2x2]
Overview of types (fundamental, compound, aggregates), type conversion, declarations, expression, operators, statements,
characters, strings, streams, string streams, file handling, functions, parameter passing, dynamic memory handling,
Excercises: Aggregates and List initialization
- Make Simple Tasks Simple!"
- Stroustrup on working in modern C++ (keynote CppCon 2014). Actual presentation starts at minute 7.
22:30: a good example of why we want to simplify code
- Writing good C++14
- Stroustrup, keynote at cppcon 15. A short overview of the state of the language and an introduction on the Cpp Core Guidelines and the GSL (guideline support library)
- Cpp Core Guidelines
- " The aim is to help people to use modern C++ effectively. By "modern C++" we mean C++11 and C++14 (and soon C++17). In other words, what would you like your code to look like in 5 years' time, given that you can start now? In 10 years' time?"
- Cpp Core Guidelines - parameter passing
- Recommendations on how to pass arguments and return results
- Simplify C++ - Simple and Clean Code vs. Performance
- Performance and simplicity don't always contradict each other!
- Simplify C++ - New C++ features - auto for variables
- A short and good introduction for using
auto for variable declarations
- Almost always auto
- Herb Sutter - his view on using auto
- [SO] When should static_cast, dynamic_cast, const_cast and reinterpret_cast be used?
- A good description on the types of type conversions in C++ (and why you shouldn't use C-style casts)
- [SO] Why should C++ programmers minimize use of 'new'?
- An overview of the C++ memory model
- [SO] Why is iostream::eof inside a loop condition considered wrong
- Using good (as in working) style for input operations
- [SO] What is the difference between a definition and a declaration?
- A simple introduction to the difference between definitions and declarations.
- [PS] Are data type declarators like int and char stored in RAM when a C program executes?
- Not really C++-specific, but a short overview of how data is stored
- [SO] What are the evaluation order guarantees introduced by C++17?
- We will (finally) have defined evaluation order in more places
- Understanding the meaning of lvalues and rvalues in C++
- A ground-up discussion on lvalues and rvalues (value categories) with lots of examples
- Building Intuition on Value Categories
- Another take on value categories
Classes [2x2] [Code example String]
Definition, declaration; members, data members, member functions, nested types, enumerators,
static members, const member functions, mutable, inline; this
(expression which gives the address for the object the member function has been called for);
access specification (public, protected, private), friend;
implicitly defined operations on class types (member access, scope operator);
special member functions (default constructor, copy constructor, copy assignment operator, destructor),
compiler generated versions of the special member functions;
initializers, type converting constructors, explicit, type converting operator functions;
recommendations for single class design.
Excercises: Aggregates and List initialization
Operator overloading [2x2]
Rules and restrictions; member or non-member?; friend or not? Overloading, optimized versions.
Guidelines and recommendations for definition and overloading of operators.
Example on copy elision
Excercises: Aggregates and List initialization | Smart pointer
- Simplify C++: C++ is NOT an object-oriented language
- Sure, we support OO, but that doesn't make it an OO language.
- ISO C++ FAQ: Additions regarding classes in C++11
- Simplify C++: Modern C++ features - Inheriting and delegating constructors
- Having constructors calling other constructors
- Simplify C++: Modern C++ features - Default initializers for member variables
- If you only want to set default values in your constructor, let the compiler do it!
- Simplify C++: Fun with(out) keyword explicit
- A type converting function may give you alot of unforseen errors without explicit declarations.
- ISO C++ FAQ: Guidelines for operator overloading
- Some rules of thumb for operator overloading for your own classes
- Simplify C++ - R-value references and move semantics
- SO: What are Aggregates and PODs and how/why are they special?
- The first answer is a great overview of POD and aggregates
- cppreference: RAII
- A short introduction to RAII
- Stroustrup: Why RAII
- A short example on RAII
- /r/cpp: Can I always depend on return value optimization as part of the standard, or do I need to think about it more?
- A good thread about (N)RVO vs. move semantics and their interplay
- Effective Modern C++, Item 17: Understand special member function generation
- A good discussion on when and why a member function is generated
Derived classes, polymorphism, RTTI [2x2] [Code example P-E-M-C]
Derivation/inheritance; base class/subclass; singe, multiple and repeated inheritance;
public, protected and private inheritance;
virtuellt inheritance (virtual); protected member access;
virtual function, pure virtual function, pure specifier (=0);
polymorf class, abstract class; static type, dynamic type;
dynamic type control, dynamic type conversion, RTTI, dynamic_cast, typeid, type_info-objects;
up-cast, down-cast, cross-cast;
Exception handling [2x2]
Try-block, function-try-block, throw-expression, catch-handler;
exception specification (for function), exception declaration (in handler);
"catch-all" handler; bad_exception;
terminate(), unexpected(), uncaught_exception(), abort();
standard exceptions (exception and subclasses); user defined exceptions;
recommendations for using exceptions.
Excercises: Geometric objects
- Simplify C++: Levels of exception safety
- On why you should think about exception safety levels
- Simplify C++: Modern C++ Features - override and final
- Why you should use the new "keywords" (identifiers with special meaning)
- Simplify C++: Modern C++ Features - keyword `noexcept`
- CppCoreGuidelines: virtual destructor
- The entire chapter C is really good here, but C35 is very important! (C120-152 is about class hierarchies)
- Simplify C++: Constructor Failures
- A note on how to handle erorrs during construction. Also an introduction to function-try-blocks.
- CppCon 2015: Richard Powell "Intro to the C++ object model" [47min]
- An intro into how the compiler sees your objects.
- CppCon 2014: Michael VanLoon "Anatomy of a smart pointer" [11min]
- modernes C++: "C++ Core Guidelines: Class Hierarchies"
- A summary of the C++ Core Guidelines rules for class hierarchies
- Pacific++ 2017: Jason Turner "Rethinking Exceptions" [1h 23min]
- On how to use exceptions and noexcept in a good way (please do!)
seminar 4 and 5
Feb 27 / 28
Function templates, class templates; declaration, definition;
template parameters, template arguments, default template parameter arguments;
template instantiation, implicit instantiation, explicit instantiation;
template specialization, implicit specialization, partial specialization, full specialization;
function templates and overload resolution;
variadic templates, parameter pack, pack expansion;
type equivalence for template classes; member templates; friend and template; alias templates;
dependent name; SFINAE;
The name rule, reference collapsing rules, move semantics, perfect forwarding;
template meta programming, type traits;
compilation models for template code.
Namespaces [2x2] (if time allows)
Namespace, namespace members, anonymous namespaces, namespace alias,
using declaration, using directive (using namespace).
Preprocessor [2x2] (if time allows)
Source code inclusion, simple macros, function macros, conditional compilation.
Policy Design for Smart Pointers |
The Curiosly Recurring Template Pattern (CRTP) |
- To SFINAE or not to SFINAE @ Flaming Dangerzone
- An overview of SFINAE vs tag dispatch and traits
- [SO] What are unevaluated contexts in C++?
- The first answer presents all the unevaluated contexts available in C++. For templates, decltype is really useful
- [SO] Is it possible to write a C++ template to check for a function's existence?
- Using SFINAE with C++11 to select implementation based on presence of a specific member
- [SO] SFINAE:: enable_if as a function argument
- An example of incorrect usage of
std::enable_if and how to fix it
- Simplify C++: Modern C++ Features - templated rvalue References and std::forward
- An overview on perfect forwarding, reference collapsing,
auto in templates
- [SO] What is the difference between a trait and a policy
- Explains both differences and the interaction between traits and policies
- Polymorphic wrapper
- An alternative to the clone pattern to create copies of a polymorphic class heirarchy
- CppCon 2014: Walter E. Brown "Modern Template Metaprogramming: A compendium, Part I"
- Some really nice template tricks and techniques. Also continue with part II
- A flexible lexicographical comparator for C++ structs
- Using templates and pointers to members to create a comparator for structs
- Doing folds with help of variadic templates
- A solution to get folds working without the tools available in C++17 fold expressions
- Why typename?
- A short presentation on why we need the typename declaration and where to use it
- Type erasure
- A short example of type erasure to store objects unrelated classes (i.e. not having the same base) in a genaral way.
- Why template parameters of dependent type names cannot be deduced, and what to do about it
- A good descussion on dependent names
seminar plan for study period Vt2 (dates will be given at a later occasion)
C++ standard library (1)
Main emphasis on containers, iterators, algorithms, function objects, and related library support.
Introduction, overview [2x2]
Overview of the STL
General overview. Containers, iterators, algorithms, function objects, utilities.
Standard containers [2x2]
Sequential containers, sequential container adaptors, ordered associative containers.
Container iterators, inserters, stream iterators.
Standard algorithms [2x2]
Algorithms (function) for operating on, e.g., containers, streams, etc.
Function objects, lambda expression [2x2]
Function objects, lambda expression
Objects that can be used as functions. Important for effective
use of containers and algorithms. Lambda exepressions is a way
to create simple function objects.
Binders, negators, function call adaptors, and standard function
objects corresponding to the arithmetic, comparison, and logical
operator in C++.
Excercises: Container Design
| Fixed Size Container
| Indexable Set
| Ordered List Iterators
| Standard Library
A collection of short segments.
The <chrono> header
The <random> header
The <ratio> header
- CppCon 2015: Michael VanLoon "STL Algorithms in Action" [1h]
- Why should you use them? Basic layout / structure and lots of good examples.
- CppCon 2015: Sean Parent "Better Code: Data Structures" [1h 4min]
- Stephan T. Lavavej's (likes to go by STL) Channel 9 lectures on the STL (part 1 here)
- There are 16 separate videos. All were released pre-C++11 but he's head of the VC implementation of the STL so he regulary shows their pre-release version implementation (which is of course a bit more refined by now)
- Lambda Overdose
- Lambdas are great, but please don't overuse them! (normal functions might be cleaner sometimes).
A collection of material that didn't really fit into a specific topic.
The range based for loop and the auto keyword
- An intro to compilers
- An overview of how the compiler processes your code from syntactic scanning to optimization and machine code generation
- 5 keywords to save your life (or at least your programming experience)
- A short walkthrough of some valuble keywords used as last lecture in the course
- CppCon 2015: Greg Law "Give me 15 minutes & I'll change your view of GDB" [15min]
- A short intro to debugging using GDB, includes the T(extual)UI and reverse debugging
- CppCon 2015: Joshua Gerrard "The dangers of C-style casts" [5min]
- Showing differences between C-style casts and the new cast styles (
static_cast etc.). "Please stop using C-style casts and use the C++ cast that you meant"
- CppCon 2015: Richard Powell "The importance of being const" [53min]
- What is
const, where to use
const, the difference beween bitwise and logical
- CppCon 2015: Atila Neves "Emacs as a C++ IDE" [16min]
- A short presentation on how to work efficiently in emacs
- CppCon 2015: Dmitri Nesteruk "CLion Tips & Tricks" [16min]
- An introduction to the CLion IDE by JetBrains. You can get all of their programming tools for free as a student here (not available at the exam)
- [SO] constexpr vs macros
- Aren't just constexpr constants the same thing as macros? (NO!)
- Some proposals for the next standard (C++2a / C++20)
- N4474: Unified call syntax
- Proposes that fun(a,b) will turn into a call to a.fun(b) if no matches for a free function is found during lookup
- N4549: Concepts
- A way of specifing exactly what is needed from the template arguments. See also a ACCU article by Andrew Sutton for a shorter and more readable version
- CppReference has a good overview as well: http://en.cppreference.com/w/cpp/language/constraints
- N4560: Ranges
- A new way of specifing a range of data (instead of pair of iterators). See also Eric Niebler's blog
- N3888: 2D graphics
- Adding a "wrapper" for the Cairo library in the standard
- Guy Davidson also has a talk on this from Meeting C++ 2017 - Dragging C++ Into the Modern Era
- [N4296] The draft version of the C++14 standard
- The draft has the same information as the actual standard, but is available for free
- [N4659] Draft of C++17
- [CppCon 2014] Chandler Carruth - Efficiency with Algorithms, Performance with Data Structures
- A short guide of how to get efficient programs with good performace by using the correct algorithms and data structures (use vector)
- [SO]: Purpose of Unions in C and C++