Hide menu

TDDD38 Advanced Programming in C++

seminars

Seminar 1 is given as a quick introduction to basic C++, actually prerequisites. If already familiar with C++11, 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 4—5 (String) and seminar 6—7 (P-E-M-C) are linked below.

Extra material will be added here during the course and on the course GitLab group.

Seminar plan for study period Vt1, week 3—10



Intro lecture 
Jan 18  

Introduction and overview [Language overview2x2]
Introduction to the course. Overview C++.


Seminar 1 
Jan  27 / 28  

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, list initialization.

Example code

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?"
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] Whatt is the difference between a definition and a declaration?
A simple itroduction 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

seminar 2 
Feb 3 / 4  

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

seminar 3 
Feb 17 / 18  

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.

An example on RAII and exceptions: Neitwork mock library

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) override and final
Simplify C++: Modern C++ Features - keyword `noexcept`
The noexcept specifier
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.

seminar 4 
Mar 2 / 3  

Links to ask and vote for questions: Mar 2 | Mar 3 Templates  [2x2] Templates
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.

Excercises: Policy Design for Smart Pointers  |  The Curiosly Recurring Template Pattern (CRTP)  |  Character Traits

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, decltype and 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

seminar plan for study period Vt2, week 14—21 (dates will be given at a later occasion)



seminar 5-?  

C++ standard library (1)
Main emphasis on containers, iterators, algorithms, function objects, and related library support.

Introduction, overview  [2x2] Introduction, overview  
General overview. Containers, iterators, algorithms, function objects, utilities.

Standard containers  [2x2] Standard containers  
Sequential containers, sequential container adaptors, ordered associative containers.

Iterators  [2x2] Iterators  
Container iterators, inserters, stream iterators.

Standard algorithms  [2x2] Standard algorithms  
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
Regular expressions
Smart pointers

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)

Extra material
A collection of material that didn't really fit into a specific topic.
The range based for loop and the auto keyword
User-defined literals

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 const
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)
Some proposals for the next standard (C++1z / C++17)
P0144R1: Structured binding
Introduces a way of defining and initializing varaibles containing return values from functions or public data members from objects. auto {iter, inserted} = my_map.insert(value);
N4100: Filesystem TS
An addition to the STL to create a POSIX-compliant filesystem interface
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
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
[N4296] The draft version of the C++14 standard
The draft has the same information as the actual standard, but is available for free



Page responsible: Eric Elfving
Last updated: 2016-04-08