Pure functions in C++

5 years ago
Anonymous $oq8ACmxlDW

https://medium.com/software-design/pure-functions-in-c-fc102fd9c5e0

C++ is not a functional programming language. Functions causing side-effects is the norm. If a compiler does not see the body of a function, it assumes that the function causes side effects. This can result in missed optimization opportunities.

Consider the following code. Here the main function for (some reason) computes the square of the total number of arguments twice and returns the sum of the squares.