diff --git a/.obsidian/workspace b/.obsidian/workspace index c1eef98..77ff95f 100644 --- a/.obsidian/workspace +++ b/.obsidian/workspace @@ -9,7 +9,7 @@ "state": { "type": "markdown", "state": { - "file": "02. PARA/01. Project(專案)/008. Sentinel.md", + "file": "02. PARA/03. Resources(資源)/C++17/for_each.md", "mode": "source", "source": true } @@ -69,7 +69,7 @@ "state": { "type": "backlink", "state": { - "file": "02. PARA/01. Project(專案)/008. Sentinel.md", + "file": "02. PARA/03. Resources(資源)/C++17/for_each.md", "collapseAll": false, "extraContext": false, "sortOrder": "alphabetical", @@ -86,7 +86,7 @@ "state": { "type": "outline", "state": { - "file": "02. PARA/01. Project(專案)/008. Sentinel.md" + "file": "02. PARA/03. Resources(資源)/C++17/for_each.md" } } } @@ -116,11 +116,11 @@ }, "active": "ec13ce58b15fa6d4", "lastOpenFiles": [ + "02. PARA/01. Project(專案)/008. Sentinel.md", "02. PARA/03. Resources(資源)/C++17/for_each.md", "02. PARA/03. Resources(資源)/讀書筆記/20220619 - 精確的力量.md", "02. PARA/03. Resources(資源)/C++17/智慧指標.md", "02. PARA/03. Resources(資源)/C++17/C++17.md", - "02. PARA/01. Project(專案)/008. Sentinel.md", "00. TOP/01. TODO.md", "02. PARA/02. Area(領域)/20150803 - Android/ADB 取得 APK 的 icon.md", "02. PARA/02. Area(領域)/20150803 - Android/ADB.md", diff --git a/02. PARA/03. Resources(資源)/C++17/for_each.md b/02. PARA/03. Resources(資源)/C++17/for_each.md index 75a4585..15c8564 100644 --- a/02. PARA/03. Resources(資源)/C++17/for_each.md +++ b/02. PARA/03. Resources(資源)/C++17/for_each.md @@ -8,4 +8,17 @@ template ); ``` -它需要3個參數,第1個是開始的iterator,第2是結束的 iterator,第3個是要用來處理的 function \ No newline at end of file +它需要3個參數,第1個是開始的iterator,第2是結束的 iterator,第3個是要用來處理的 function。 + +一個簡單的例子,有一個array,需要把每一個數都加1: +```cpp +vector arr1 = { 4, 5, 8, 3, 1 }; + +for_each( + arr1.begin(), // _Start + arr1.end(), // _Last + [](int& val) { // _Func + val += 1; + } +); +``` \ No newline at end of file