20.7 — Lambda captures

In the previous lesson (), we introduced this example: #include <algorithm> #include <array> #include <iostream> #include <string_view> int main() { std::array<std::string_view, 4> arr{ “apple”, “banana”, “walnut”, “lemon” }; auto found{ std::find_if(arr.begin(), arr.end(), [](std::string_view str) { return str.find(“nut”) != std::string_view::npos; }) }; if (found == arr.end()) { std::cout << “No nuts\n”; …

20.6 — Introduction to lambdas (anonymous functions)

Consider this snippet of code that we introduced in lesson : #include <algorithm> #include <array> #include <iostream> #include <string_view> // Our function will return true if the element matches bool containsNut(std::string_view str) { // std::string_view::find returns std::string_view::npos if it doesn’t find // the substring. Otherwise it returns the index where …