#include <iostream>
#include <functional>
void call_each(int begin, int end, std::function<void(int)> 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(int begin, int end, std::function<void(int)> f)
{
for (int i=begin; i<end; ++i)
{
f(i);
}
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8ZnVuY3Rpb25hbD4KCnZvaWQgY2FsbF9lYWNoKGludCBiZWdpbiwgaW50IGVuZCwgc3RkOjpmdW5jdGlvbjx2b2lkKGludCk+IGYpOwoKc3RydWN0IHRlc3QxCnsKCXZvaWQgb3BlcmF0b3IoKShpbnQgaSkgeyBzdGQ6OmNvdXQgPDwgIlsxXSAiIDw8IGkgPDwgc3RkOjplbmRsOyB9Cn07Cgp2b2lkIHRlc3QyKGludCBpKQp7CglzdGQ6OmNvdXQgPDwgIlsyXSAiIDw8IGkgPDwgc3RkOjplbmRsOwp9CgppbnQgbWFpbigpIHsKCWNhbGxfZWFjaCggMSwgNCwgdGVzdDEoKSApOwoJY2FsbF9lYWNoKCA0LCA3LCB0ZXN0MiApOwoJcmV0dXJuIDA7Cn0KCnZvaWQgY2FsbF9lYWNoKGludCBiZWdpbiwgaW50IGVuZCwgc3RkOjpmdW5jdGlvbjx2b2lkKGludCk+IGYpCnsKCWZvciAoaW50IGk9YmVnaW47IGk8ZW5kOyArK2kpCgl7CgkJZihpKTsKCX0KfQoK