Functional Programming in C++
4h 25mIntermediate2025-04-01
Authors

Troy Miles
Award-winning Software Engineer, Speaker, and Author
Course details
Explore the application of functional programming principles in modern C++ using features introduced in C++17, C++20, and C++23. In this course, instructor Troy MIles shows you how to write more modular, expressive, and efficient code by leveraging features such as lambdas, ranges, coroutines, and concepts. Along the way, discover how functional pipelines, metaprogramming, and the constexpr specifier can transform your approach to problem-solving in C++. This course also covers functional reactive programming, pattern matching, and the integration of functional and imperative styles to help you master advanced C++ techniques.
Learning objectives
Apply modern C++ features, such as lambdas, ranges, and coroutines, to write more efficient and expressive functional code.
Analyze the benefits of functional programming in C++ by comparing functional and imperative solutions to common problems.
Evaluate the use of concepts and type constraints to ensure type-safe generic programming in C++20 and C++23.
Create functional pipelines using the ranges library to transform and process data quickly and efficiently.
Synthesize functional programming principles with metaprogramming and the constexpr specifier to implement compile-time computations and improve performance.
Learning objectives
Apply modern C++ features, such as lambdas, ranges, and coroutines, to write more efficient and expressive functional code.
Analyze the benefits of functional programming in C++ by comparing functional and imperative solutions to common problems.
Evaluate the use of concepts and type constraints to ensure type-safe generic programming in C++20 and C++23.
Create functional pipelines using the ranges library to transform and process data quickly and efficiently.
Synthesize functional programming principles with metaprogramming and the constexpr specifier to implement compile-time computations and improve performance.
Skills covered
C++Programming FoundationsProgramming LanguagesOpen SourceSoftware DevelopmentOne-Off
Concepts
0. Introduction
- 01 - Introduction
1. Functional Programming in Modern C++
- 02 - What is functional programming
- 03 - Lambdas and closures
- 04 - Standard algorithms (transform, views, accumulate)
- 05 - Accumulate and reduce
- 06 - Partial application and currying (std - - bind)
- 07 - Composing functions with standard library algorithms
- 08 - Challenge - Factorial continuous add
- 09 - Solution - Factorial continuous add
2. Concepts and Type Constraints in C++20
- 10 - Why concepts
- 11 - Basic concept syntax
- 12 - Defining custom concepts
- 13 - Combining concepts
- 14 - Concepts vs. SFINAE (Pre-C++20)
- 15 - Challenge - Function constrained by concepts
- 16 - Solution - Function constrained by concepts
3. Ranges and Pipelines in C++20 23
- 17 - Ranges and pipelines in C++20 23
- 18 - Why use ranges (transforming a collection)
- 19 - Combining filters and transforms
- 20 - Lazy evaluation with coroutines (infinite Fibonacci generator)
- 21 - Combining multiple range operations to transform collections
- 22 - Challenge - Build a functional pipeline
- 23 - Solution - Build a Functional pipeline
4. Template Metaprogramming and constexpr
- 24 - Template metaprogramming and constexpr
- 25 - Recursive templates in C++
- 26 - Factorial using constexpr
- 27 - Advanced compile-time computation - Fibonacci sequence
- 28 - Why compile-time matrix multiplication
- 29 - Challenge - Implement a constexpr factorial
- 30 - Solution - Implement a constexpr factorial
5. Higher-Order Functions and Composition in C++23
- 31 - Introduction to higher-order functions
- 32 - Using std - - move only function for higher-order functions
- 33 - Function composition with lambdas and std - - invoke
- 34 - Benefits of composing functions for more modular code
- 35 - Real-world use cases of higher-order functions in modern C++
- 36 - Challenge - Function composition pipeline
- 37 - Solution - Function composition pipeline
6. Functional Programming Libraries
- 38 - Using functional-style algorithms using the STL
- 39 - Transforming and summing a list
- 40 - Filtering values with std - - ranges - - filter (C++20)
- 41 - Tuple manipulation with Boost.Hana
- 42 - Combining Boost.Hana with standard functional techniques in C++
- 43 - Challenge - Filtering and transforming with STL and Boost.Hana
- 44 - Solution - Filtering and transforming with STL and Boost.Hana
7. Functional Reactive Programming
- 45 - Functional reactive programming
- 46 - Simple RxCpp stream
- 47 - Coroutine with RxCpp and ranges
- 48 - Real-time data stream processing in a functional manner
- 49 - Benefits of functional programming for asynchronous event handling
- 50 - Challenge - Word frequency counter with RxCpp
- 51 - Solution - Word frequency counter with RxCpp
8. Pattern Matching and Variants in C++23
- 52 - Introduction to pattern matching and its functional programming origins
- 53 - Basic pattern matching with std - - variant
- 54 - Type-specific overloads with std - - visit
- 55 - Improving code clarity with pattern matching techniques
- 56 - Applications of std - - variant and std - - visit in real-world scenarios
- 57 - Challenge - Pattern matching with std - - variant
- 58 - Solution - Pattern matching with std - - variant
9. Advanced Coroutines and Asynchronous Programming
- 59 - Advanced coroutines and asynchronous programming
- 60 - Lazy sequence generator with co yield
- 61 - Asynchronous task management with coroutines
- 62 - Combining coroutines with lazy evaluation for efficient task execution
- 63 - Handling concurrent tasks in a functional manner
- 64 - Challenge - Asynchronous task manager
- 65 - Solution - Asynchronous task manager
10. Combining Functional and Imperative Styles
- 66 - Combining functional and imperative styles
- 67 - Functional pipelines with imperative loops
- 68 - Emulating immutable data with std - - shared ptr
- 69 - Refactoring imperative code into a functional style for clarity
- 70 - Balancing performance and maintainability using hybrid programming styles
- 71 - Challenge - Refactor imperative code into a functional style
- 72 - Solution - Refactor imperative code into a functional style