#include <array>
int myfun(const std::array<int, 10>& values)
{
static const auto funImpl = [&]() -> int
{
int sum = 0;
for (int i = 0; i < 10; ++i)
{
sum += values[i];
}
return sum;
};
return funImpl();
}
#include <iostream>
int main()
{
std::array<int, 10> arr1 = {0,1,2,3,4,5,6,7,8,9}; // sum 45
std::array<int, 10> arr2 = {10,1,2,3,4,5,6,7,8,9}; // sum 55
std::cout<< myfun(arr1) << std::endl;
std::cout<< myfun(arr2) << std::endl;
}
I2luY2x1ZGUgPGFycmF5PgoKaW50IG15ZnVuKGNvbnN0IHN0ZDo6YXJyYXk8aW50LCAxMD4mIHZhbHVlcykKewogICAgc3RhdGljIGNvbnN0IGF1dG8gZnVuSW1wbCA9IFsmXSgpIC0+IGludAogICAgewogICAgICAgIGludCBzdW0gPSAwOwoKICAgICAgICBmb3IgKGludCBpID0gMDsgaSA8IDEwOyArK2kpCiAgICAgICAgewogICAgICAgICAgICBzdW0gKz0gdmFsdWVzW2ldOwogICAgICAgIH0KICAgICAgICByZXR1cm4gc3VtOwogICAgfTsKCiAgICByZXR1cm4gZnVuSW1wbCgpOwp9CgojaW5jbHVkZSA8aW9zdHJlYW0+CgppbnQgbWFpbigpCnsKICAgc3RkOjphcnJheTxpbnQsIDEwPiBhcnIxID0gezAsMSwyLDMsNCw1LDYsNyw4LDl9OyAvLyBzdW0gNDUKICAgc3RkOjphcnJheTxpbnQsIDEwPiBhcnIyID0gezEwLDEsMiwzLDQsNSw2LDcsOCw5fTsgLy8gc3VtIDU1CgogICBzdGQ6OmNvdXQ8PCBteWZ1bihhcnIxKSA8PCBzdGQ6OmVuZGw7CiAgIHN0ZDo6Y291dDw8IG15ZnVuKGFycjIpIDw8IHN0ZDo6ZW5kbDsKfQ==