#include <iostream>
struct test1
{
void operator()(int i)
{
std::cout << "[1] " << i << std::endl;
}
};
void test2(int i)
{
std::cout << "[2] " << i << std::endl;
}
void test3_impl(int i)
{
std::cout << "[3] " << i << std::endl;
}
void (*test3)(int) = test3_impl;
template <typename Function>
void call_each(int begin, int end, Function f)
{
for (int i=begin; i<end; ++i)
f(i);
}
int main() {
call_each(1, 4, test1());
call_each(2, 7, test2);
call_each(7, 10, test3);
//call_each(10, 13, [](int i) -> void { std::cout << "[4] " << i << std::endl; });
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKc3RydWN0IHRlc3QxCnsKICB2b2lkIG9wZXJhdG9yKCkoaW50IGkpCiAgewogICAgc3RkOjpjb3V0IDw8ICJbMV0gIiA8PCBpIDw8IHN0ZDo6ZW5kbDsKICB9Cn07Cgp2b2lkIHRlc3QyKGludCBpKQp7CiAgc3RkOjpjb3V0IDw8ICJbMl0gIiA8PCBpIDw8IHN0ZDo6ZW5kbDsKfQoKdm9pZCB0ZXN0M19pbXBsKGludCBpKQp7CiAgc3RkOjpjb3V0IDw8ICJbM10gIiA8PCBpIDw8IHN0ZDo6ZW5kbDsKfQp2b2lkICgqdGVzdDMpKGludCkgPSB0ZXN0M19pbXBsOwoKdGVtcGxhdGUgPHR5cGVuYW1lIEZ1bmN0aW9uPgp2b2lkIGNhbGxfZWFjaChpbnQgYmVnaW4sIGludCBlbmQsIEZ1bmN0aW9uIGYpCnsKICBmb3IgKGludCBpPWJlZ2luOyBpPGVuZDsgKytpKQogICAgZihpKTsKfQoKaW50IG1haW4oKSB7CiAgY2FsbF9lYWNoKDEsIDQsIHRlc3QxKCkpOwogIGNhbGxfZWFjaCgyLCA3LCB0ZXN0Mik7CiAgY2FsbF9lYWNoKDcsIDEwLCB0ZXN0Myk7CiAgLy9jYWxsX2VhY2goMTAsIDEzLCBbXShpbnQgaSkgLT4gdm9pZCB7IHN0ZDo6Y291dCA8PCAiWzRdICIgPDwgaSA8PCBzdGQ6OmVuZGw7IH0pOwp9Cg==