Function is pure if:
- It has no semantically observable side effects
- Always returns the same result given the same input
So the function can still have a state, but it should not be observable. For example:
int foo(std::vector<int> v) {
static std::vector<int> tmp;
tmp.resize(v.size);
std::transform(v.begin(), v.end(), tmp.begin(), [](int a) {return a * a;});
return std::accumulate(tmp.begin(), tmp.end(), 0);
}
function foo has a state (static vector), however it is not semantically observable, thus its pure. Its a stupid function, but it should show the point.