You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: en/03_Drawing_a_triangle/00_Setup/03_Physical_devices_and_queue_families.adoc
+14-9Lines changed: 14 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -199,6 +199,7 @@ void pickPhysicalDevice() {
199
199
throw std::runtime_error("failed to find a suitable GPU!");
200
200
}
201
201
}
202
+
----
202
203
203
204
=== Understanding the nested lambda functions
204
205
@@ -209,9 +210,11 @@ The `pickPhysicalDevice()` function above uses several nested lambda functions,
209
210
Lambda functions (or lambda expressions) are a C++ feature that allows you to define anonymous functions inline. They're especially useful for short operations that you don't need to define as separate named functions.
210
211
211
212
The basic syntax of a lambda is:
212
-
```cpp
213
+
214
+
[source,cpp]
215
+
----
213
216
[capture-list](parameters) { body }
214
-
```
217
+
----
215
218
216
219
- The `capture-list` specifies which variables from the surrounding scope are accessible inside the lambda
217
220
- `parameters` are the input parameters, just like in regular functions
@@ -221,14 +224,15 @@ The basic syntax of a lambda is:
221
224
222
225
In our `pickPhysicalDevice()` function, we use `std::ranges::find_if` with a lambda to find the first suitable device:
223
226
224
-
```cpp
227
+
[source,cpp]
228
+
----
225
229
const auto devIter = std::ranges::find_if(devices,
226
230
[&](auto const & device) {
227
231
// Lambda body that checks if the device is suitable
228
232
// ...
229
233
return isSuitable;
230
234
});
231
-
```
235
+
----
232
236
233
237
The `[&]` capture list means this lambda can access all variables from the
234
238
surrounding scope by reference. This is necessary because we need to access
@@ -240,25 +244,27 @@ convenience andclarity as goals in mind.
240
244
241
245
Inside the main lambda, we have another lambda that checks if a queue family supports graphics operations:
242
246
243
-
```cpp
247
+
[source,cpp]
248
+
----
244
249
const auto qfpIter = std::ranges::find_if(queueFamilies,
0 commit comments