Pure functions are the core building blocks of functional programming. They are immutable functions, which allow them to be simple and predictable. Writing pure functions in C++ is easy, but there are a few things that you'll need to be aware of. Since functions in C++ are mutable by default, we need to learn the syntax that tells the compiler how to prevent mutations. We'll also explore how to separate mutable code from immutable code.
The following topics will be covered in this chapter:
- Understanding what a pure function is
- Writing pure functions in C++ and functions that return multiple arguments using tuples
- Ensuring immutability in C++ pure functions
- Understanding why I/O is mutable and needs to be separated from pure functions