#include <iostream>
#include <vector>
using namespace std;
template<int RepeatTimes, typename F, class ... mutrArgs>
void run(
vector<int>& vec,
F mutr,
mutrArgs ... args
)
{
for (int times{0} ; times < RepeatTimes ; ++times)
for (auto& item : vec)
mutr(item, args...);
}
void adder(int& i, const int& val)
{
i += val;
}
int main()
{
vector<int> v{0,1,2,3,4,5,6,7,8,9};
const int addValue{4};
run<2>(
v,
&adder,
addValue
);
for (auto i : v)
cout << i << " ";
cout << endl;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKdGVtcGxhdGU8aW50IFJlcGVhdFRpbWVzLCB0eXBlbmFtZSBGLCBjbGFzcyAuLi4gbXV0ckFyZ3M+CnZvaWQgcnVuKAogICAgdmVjdG9yPGludD4mIHZlYywKICAgIEYgbXV0ciwKICAgIG11dHJBcmdzIC4uLiBhcmdzCikKewogICAgZm9yIChpbnQgdGltZXN7MH0gOyB0aW1lcyA8IFJlcGVhdFRpbWVzIDsgKyt0aW1lcykKICAgICAgICBmb3IgKGF1dG8mIGl0ZW0gOiB2ZWMpCiAgICAgICAgICAgIG11dHIoaXRlbSwgYXJncy4uLik7Cn0KCnZvaWQgYWRkZXIoaW50JiBpLCBjb25zdCBpbnQmIHZhbCkKewogICAgaSArPSB2YWw7Cn0KCmludCBtYWluKCkKewogICAgdmVjdG9yPGludD4gdnswLDEsMiwzLDQsNSw2LDcsOCw5fTsKICAgIGNvbnN0IGludCBhZGRWYWx1ZXs0fTsKICAgIHJ1bjwyPigKICAgICAgICAgICAgdiwKICAgICAgICAgICAgJmFkZGVyLAogICAgICAgICAgICBhZGRWYWx1ZQogICAgICAgICAgICAgICAgICAgICAgKTsKICAgIGZvciAoYXV0byBpIDogdikKICAgICAgICBjb3V0IDw8IGkgPDwgIiAiOwogICAgY291dCA8PCBlbmRsOwp9Cg==