#include <iostream>
#include <functional>
int add(int a, int b){return a+b;}
int sub(int a, int b){return a-b;}
int mul(int a, int b){return a*b;}
int main()
{
// array of pointers to functions
int (*arr1[])(int, int) = {add, sub, mul};
// array of std::reference_wrappers
std::reference_wrapper<int(int, int)> arr2[] = {std::ref(add), std::ref(sub), std::ref(mul)};
// array of std::functions
std::function<int(int,int)> arr3[] = {add, sub, mul};
// let's use them
std::cout << arr1[0](1, 2) << ' ' << arr1[1](1,2) << ' ' << arr1[2](1,2) << '\n'
<< arr2[0](1, 2) << ' ' << arr2[1](1,2) << ' ' << arr2[2](1,2) << '\n'
<< arr3[0](1, 2) << ' ' << arr3[1](1,2) << ' ' << arr3[2](1,2) << '\n';
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8ZnVuY3Rpb25hbD4KaW50IGFkZChpbnQgYSwgaW50IGIpe3JldHVybiBhK2I7fQppbnQgc3ViKGludCBhLCBpbnQgYil7cmV0dXJuIGEtYjt9CmludCBtdWwoaW50IGEsIGludCBiKXtyZXR1cm4gYSpiO30KCmludCBtYWluKCkKewogICAgLy8gYXJyYXkgb2YgcG9pbnRlcnMgdG8gZnVuY3Rpb25zCiAgICBpbnQgKCphcnIxW10pKGludCwgaW50KSA9IHthZGQsIHN1YiwgbXVsfTsKICAgIC8vIGFycmF5IG9mIHN0ZDo6cmVmZXJlbmNlX3dyYXBwZXJzCiAgICBzdGQ6OnJlZmVyZW5jZV93cmFwcGVyPGludChpbnQsIGludCk+IGFycjJbXSA9IHtzdGQ6OnJlZihhZGQpLCBzdGQ6OnJlZihzdWIpLCBzdGQ6OnJlZihtdWwpfTsKICAgIC8vIGFycmF5IG9mIHN0ZDo6ZnVuY3Rpb25zCiAgICBzdGQ6OmZ1bmN0aW9uPGludChpbnQsaW50KT4gYXJyM1tdID0ge2FkZCwgc3ViLCBtdWx9OwoKICAgIC8vIGxldCdzIHVzZSB0aGVtCiAgICBzdGQ6OmNvdXQgPDwgYXJyMVswXSgxLCAyK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