fork download
  1. #include <array>
  2.  
  3. int myfun(const std::array<int, 10>& values)
  4. {
  5. static const auto funImpl = [&]() -> int
  6. {
  7. int sum = 0;
  8.  
  9. for (int i = 0; i < 10; ++i)
  10. {
  11. sum += values[i];
  12. }
  13. return sum;
  14. };
  15.  
  16. return funImpl();
  17. }
  18.  
  19. #include <iostream>
  20.  
  21. int main()
  22. {
  23. std::array<int, 10> arr1 = {0,1,2,3,4,5,6,7,8,9}; // sum 45
  24. std::array<int, 10> arr2 = {10,1,2,3,4,5,6,7,8,9}; // sum 55
  25.  
  26. std::cout<< myfun(arr1) << std::endl;
  27. std::cout<< myfun(arr2) << std::endl;
  28. }
Success #stdin #stdout 0s 2884KB
stdin
Standard input is empty
stdout
45
45