vault backup: 2025-02-10 17:27:57

This commit is contained in:
2025-02-10 17:27:57 +08:00
parent 60a1c02c6a
commit 5752038f86
159 changed files with 1 additions and 1 deletions

24
20.02. CPP/for_each.md Normal file
View File

@@ -0,0 +1,24 @@
for_each 是一個 function它的原型是
```cpp
template<class InputIterator, class Function>
Function for_each(
InputIterator _Start,
InputIterator _Last,
Function _Func
);
```
它需要3個參數第1個是開始的iterator第2是結束的 iterator第3個是要用來處理的 function。
一個簡單的例子有一個array需要把每一個數都加1
```cpp
vector<int> arr1 = { 4, 5, 8, 3, 1 };
for_each(
arr1.begin(), // _Start
arr1.end(), // _Last
[](int& val) { // _Func
val += 1;
}
);
```