Functional-style C++

Slide header

Masterclass on functional-style C++.


More often than not, C++ code is written in an imperative, object-oriented programming (OOP) style. In OOP, we encapsulate data state in abstractions, called objects, exposing an API to the outside world. The imperative style essentially means the code explicitly dictates the computer how a program must operate. However, frequently it makes sense to express what the program should accomplish, without specifying exactly how. This so-called declarative style generally results in code that is shorter, easier to reason about, and therefore less prone to bugs. Functional programming is a declarative programming style and has seen a strong increase in popularity over the last decades, even though it has been used in programming since the 1950s. C++ also caters for functional programming, especially so since the latest releases of the language. Join me in this journey of functional-style programming, and learn about higher-order functions, function purity, currying, algebraic data types, ranges and more. Being able to wield multiple programming paradigms effectively will definitely improve your productivity and the quality of your code.


This session is for professionals in software engineering, level novice to advanced, interested in C++. The focus of the content will be on the concepts in functional programming, applied to C++. Even if you can only read C++, there will be benefit from learning how the functional programming techniques are applied.

Topic listing

These are the main topics addressed in the talk:

  1. Introduction
  • Paradigms in the C++ ecosystem
  • Comparing OOP and FP
  • Imperative vs. declarative paradigms
  • Imperative vs. declarative C++
  • Main concepts in FP
  1. Higher-order functions and function objects
  • What is a higher-order function?
  • Function objects in C++
  • Implementing function objects
  • Passing functions as arguments
  • Partial function application
  • Currying
  1. Immutability and pure functions
  • Reasoning about code
  • Function purity
  • Pure functions and concurrency
  • Immutability in C++
  1. Lazy evaluation and ranges
  • Lazy evaluation
  • Ranges
  • Algorithms, views, actions
  1. Functional data structures and types
  • Functional data structures
  • Algebraic data types (ADTs)
  • Domain modeling with ADTs