#include <algorithm>
#include <iterator>
#include <iostream>
#include <memory>
#include <numeric>
#include <vector>

using namespace std;

struct foo {
    int b() const { return _b; }
    int a() const { return _a; }
    int r() const { return _r; }
    const int _b;
    const int _a;
    const int _r;
};

template <int (foo::*T)() const>
int func(const int init, const foo* i) { return init + (i->*T)(); }

int main() {
	const vector<foo*> foos { new foo{ 0, 1, 2 }, new foo{ 3, 4, 5 }, new foo{ 6, 7, 8 } };
 
	cout << accumulate(cbegin(foos), cend(foos), 0, &func<&foo::r>);
	
	for_each(begin(foos), end(foos), default_delete<foo>());
}