#include <iostream>
#include <functional>
void call_each_impl(int begin, int end, std::function<void(int)> f);
template <typename F>
void call_each(int begin, int end, F f)
{
call_each_impl(begin, end, f);
}
struct test1
{
void operator()(int i) { std::cout << "[1] " << i << std::endl; }
};
void test2(int i)
{
std::cout << "[2] " << i << std::endl;
}
int main() {
call_each( 1, 4, test1() );
call_each( 4, 7, test2 );
return 0;
}
void call_each_impl(int begin, int end, std::function<void(int)> f)
{
for (int i=begin; i<end; ++i)
{
f(i);
}
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8ZnVuY3Rpb25hbD4KCnZvaWQgY2FsbF9lYWNoX2ltcGwoaW50IGJlZ2luLCBpbnQgZW5kLCBzdGQ6OmZ1bmN0aW9uPHZvaWQoaW50KT4gZik7Cgp0ZW1wbGF0ZSA8dHlwZW5hbWUgRj4Kdm9pZCBjYWxsX2VhY2goaW50IGJlZ2luLCBpbnQgZW5kLCBGIGYpCnsKCWNhbGxfZWFjaF9pbXBsKGJlZ2luLCBlbmQsIGYpOwp9CgpzdHJ1Y3QgdGVzdDEKewoJdm9pZCBvcGVyYXRvcigpKGludCBpKSB7IHN0ZDo6Y291dCA8PCAiWzFdICIgPDwgaSA8PCBzdGQ6OmVuZGw7IH0KfTsKCnZvaWQgdGVzdDIoaW50IGkpCnsKCXN0ZDo6Y291dCA8PCAiWzJdICIgPDwgaSA8PCBzdGQ6OmVuZGw7Cn0KCmludCBtYWluKCkgewoJY2FsbF9lYWNoKCAxLCA0LCB0ZXN0MSgpICk7CgljYWxsX2VhY2goIDQsIDcsIHRlc3QyICk7CglyZXR1cm4gMDsKfQoKdm9pZCBjYWxsX2VhY2hfaW1wbChpbnQgYmVnaW4sIGludCBlbmQsIHN0ZDo6ZnVuY3Rpb248dm9pZChpbnQpPiBmKQp7Cglmb3IgKGludCBpPWJlZ2luOyBpPGVuZDsgKytpKQoJewoJCWYoaSk7Cgl9Cn0KCg==