functional programming in C++ using <functional> and <algorithm>