Thinking Functionally in C++ - Brian Ruth - CppCon 2023

Learn how to apply functional programming principles to your C++ code, improve performance and readability by separating actions, calculations, and data, and see how RAII, lambda functions, and ranges can be leveraged for better code design.

Key takeaways
  • C++ is a multi-paradigm language, allowing for functional, imperative, and object-oriented programming.
  • Identifying actions, calculations, and data is crucial for thinking functionally.
  • Actions involve side effects, while calculations are predictable and deterministic.
  • Data is context-dependent, and functional programming helps reduce side effects by separating actions and calculations.
  • Lambda functions can capture values and store them for later use.
  • Ranges and views are used to create lazy iterators, reducing unnecessary memory allocations.
  • Functional concepts like filter, map, and reduce can be applied to C++ code to improve performance and readability.
  • Calculations can be reused by lifting them up to avoid repeated iterations.
  • RAII can be used to manage resources and reduce unnecessary work.
  • Functional programming is about separating concerns and identifying actions, calculations, and data.