teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

2

修正

2020/03/10 17:43

投稿

asm
asm

スコア15149

answer CHANGED
@@ -28,6 +28,8 @@
28
28
  ```c++
29
29
  #include <functional>
30
30
  #include <vector>
31
+ #include <numeric>
32
+
31
33
  using Func1 = std::function<int(int)>;
32
34
 
33
35
  Func1 process1(int x){ return [x](int y){return x + y + 1;}; }

1

修正

2020/03/10 17:43

投稿

asm
asm

スコア15149

answer CHANGED
@@ -40,6 +40,8 @@
40
40
  ary.push_back(process1(2));
41
41
  ary.push_back(process2(3));
42
42
  ary.push_back(process1(4));
43
- std::cout << ary[0](ary[1](ary[2](5)));
43
+ // std::cout << ary[0](ary[1](ary[2](5)));
44
+ std::cout << std::accumulate(ary.rbegin(), ary.rend(), 5,
45
+ [](int x, Func1 f){return f(x);});
44
46
  }
45
47
  ```