#include <iostream>
#include <vector>
typedef void (*func_type)();
void func1() { std::cout << "func1\n"; }
void func2() { std::cout << "func2\n"; }
void func3() { std::cout << "func3\n"; }
void func4() { std::cout << "func4\n"; }
void func5() { std::cout << "func5\n"; }
template <typename iter_type>
void execute(iter_type beg, const iter_type& end)
{
while (beg != end)
(*beg++)();
}
void with_new_and_array()
{
func_type* funcs = new func_type[5];
funcs[0] = func1;
funcs[1] = func2;
funcs[2] = func3;
funcs[3] = func4;
funcs[4] = func5;
execute(funcs, funcs + 5);
delete [] funcs;
}
void with_vector()
{
std::vector<func_type> funcs = { func1, func2, func3, func4, func5 };
execute(funcs.begin(), funcs.end());
}
int main()
{
with_new_and_array();
with_vector();
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgoKdHlwZWRlZiB2b2lkICgqZnVuY190eXBlKSgpOwoKdm9pZCBmdW5jMSgpIHsgc3RkOjpjb3V0IDw8ICJmdW5jMVxuIjsgfQp2b2lkIGZ1bmMyKCkgeyBzdGQ6OmNvdXQgPDwgImZ1bmMyXG4iOyB9CnZvaWQgZnVuYzMoKSB7IHN0ZDo6Y291dCA8PCAiZnVuYzNcbiI7IH0Kdm9pZCBmdW5jNCgpIHsgc3RkOjpjb3V0IDw8ICJmdW5jNFxuIjsgfQp2b2lkIGZ1bmM1KCkgeyBzdGQ6OmNvdXQgPDwgImZ1bmM1XG4iOyB9CgoKdGVtcGxhdGUgPHR5cGVuYW1lIGl0ZXJfdHlwZT4Kdm9pZCBleGVjdXRlKGl0ZXJfdHlwZSBiZWcsIGNvbnN0IGl0ZXJfdHlwZSYgZW5kKQp7CiAgICB3aGlsZSAoYmVnICE9IGVuZCkKICAgICAgICAoKmJlZysrKSgpOwp9Cgp2b2lkIHdpdGhfbmV3X2FuZF9hcnJheSgpCnsKICAgIGZ1bmNfdHlwZSogZnVuY3MgPSBuZXcgZnVuY190eXBlWzVdOwogICAgZnVuY3NbMF0gPSBmdW5jMTsKICAgIGZ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