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 45 (String) and seminar 67 (P-E-M-C) are linked below.
Seminar plan for study period Vt1, week 310
Introduction and overview [Language overview; 2x2]
Introduction to the course. Overview C++.
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,
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
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
Feb 17 / 18
Links to ask and vote for questions: Feb 17 | Feb 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)
- 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.
Mar 2 / 3
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) |
seminar plan for study period Vt2, week 1421 (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]
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 range based for loop and the auto keyword
The <chrono> header
The <random> header
The <ratio> header