Advanced Real-Time Modern C++

Course category
Training area
Course code
AC++11-502
Duration
5 days
Additional information
Available for on-site delivery only.

The term ‘Modern C++’ is used to describe the current best practices for the use of C++.  In some cases, this may mean new capabilities of the language; in other cases it means more effective ways of performing familiar programming tasks.
 
This advanced course is designed to transition experienced C++ programmers to the latest incarnation of the C++ language.  The focus is to teach good programming practice using Modern C++ and to put the latest features of the language into context.

Course objectives:

  • Provide a background into the C++ features that have changed
  • Provide an overview of the new language features
  • Understand how the new features change C++ programming style
  • Give practical experience of the new features
  • Give the confidence to apply these new concepts to your next project

Delegates will learn:

  • The new extensions to the C++ language
  • Some of the performance impacts of the new features
  • The extensions to the Standard Template Library
  • Some of the new Standard Libraries
  • An introduction to the new C++ threading model

Pre-requisites:

This course is not intended to be a comprehensive C++ course and it is expected that students will already have a solid working knowledge of C++98, in particular.

  • Object Oriented design
  • RAII
  • The Standard Template Library

Ideally, attendees would have completed the Feabhas course C++-501 C++ for Embedded Developers.

Who should attend? 
This course is aimed at experienced C++ developers who want to quickly understand the new facilities of C++17.

Duration:

  • Five days

Course materials:

  • Delegate handbook
  • Delegate datakey

Course workshop: 

Lectures and exercises. Formal lectures are supplemented with hands-on exercises, with students developing and coding solutions for a programming case study.

Part 1 - Core concepts

The C++ object model
• Declaration and definition
• Brace initialisation syntax
• ODR-use and 'The One Declaration Rule'
• Object scope and lifetime
• The C++ object (memory) model

Expressions
• Expressions 
• l-values and r-values
• statements 
• happens-before / happens-after

User defined types
• Aggregate types – structs
• Brace elision
• Classes
• Non-Static Data Member Initialisers
• Delegating constructors
• std::initializer_list

Functions
• Function call ABIs
• Input, Output and Input-Output parameters
• Const correctness
• Copy elision
• Attributes

Type deduction
• Automatic type deduction
• Automatic function return-type deduction
• Structured bindings
• Using aliases

Constants
• Literals
• Const qualification
• Constexpr
• Constexpr functions
• enum class
• enum underlying type

Connecting objects
• Unidirectional Associations
• Bidirectional association
• Forward declarations

Composition
• Nested object construction

Creating substitutable types
• Specialisation vs inheritance
• Substitution
• The Liskov Substitution principle
• The virtual function ABI

Abstract Base Classes
• The Single Responsibility principle
• Pure virtual functions
• Abstract types
• Dynamic cast

Realising interfaces
• The Dependency Inversion principle
• The Interface concept
• Pure virtual classes
• The Interface Segregation principle

Part 2 - STL containers

Sequence containers
• The problems with C-style arrays
• std::array
• Dynamic sequence containers
• Emplacement

Algorithms
• The iterator model
• Range-for 
• Algorithms

Associative containers
• std::pair
• Sets and maps
• Hash-maps - std::unordered_map

Callable objects
• Lambda expressions
• The 'block-scoped function' concept
• Generic lambdas
• std::function

Variable types
• Generic structures – std::tuple
• Nullable types – std::optional
• Type-safe unions – std::variant
• The Visitor pattern
• Type-safe void pointers – std::any

Part 3 - Resource management

Resource management
• The resource lifetime problem
• Overloading the copy constructor
• Overloading the assignment operator
• The 'Rule of the Big Three'
• The copy-swap idiom

Move semantics
• The cost of copying
• 'Resource pilfering'
• Move constructors
• The Rule of Four and A Half
• Move assignment
• std::move
• Compiler overload provision for copy / swap

Smart pointers
• The problem with raw pointers for memory management
• std::unique_ptr
• std::shared_ptr
• std_weak_ptr

Part 4 - Templates

Template functions
• The problems with function-like macros
• Template functions
• Template parameter type deduction
• The forwarding reference idiom
• Template function overloading

Template classes
• Generic classes
• Template type deduction
• Template deduction guidelines

Templates and polymorphism
• The cost of virtual interfaces
• Policy patterns

Perfect forwarding
• Variadic templates
• std::forward
• std::forward vs std::move

Conditional coding
• Condition compilation with the pre-processor
• Template class explicit and partial specialisation
• Compile-time function selection (SFINAE)
• Compile-time implementation selection - constexpr-if

Part 5 - Concurrency

Threading
• Concurrency vs parallelism
• std::thread
• Run policies
• Polymorphic threads
• Waiting for threads to finish
• Detaching threads

Mutual exclusion
• Race conditions
• Mutual exclusion
• The scope-locked idiom
• std::lock_guard and std::unique_lock

Atomic types
• Shared objects in multiprocessor environments
• Why volatile is inappropriate
• Atomic types
• Load-acquire / Store-release barriers
• When atomic types are inadequate

Monitors
• Condition variables
• The Guarded Suspension pattern

Asynchronous tasks
• The Asynchronous Message pattern
• The Promise / Future pattern
• Packaged tasks
• std::async
• Throwing exceptions between threads
• Launch policies

Appendices

Appendix - User defined literals
• 'Rommable' types
• operator ""

Appendix - Exception handling
• Error handling strategies
• Throwing / catching exceptions
• Building an exception hierarchy
• Standard library exceptions
• Specifying your exception contract

Appendix - Regular expressions
• Regular expressions
• Regex syntax
• Searching using regexes
• Complete and partial matches