These videos seem absolutely underrated. I’ve been working with Python for the last 17 years and not much with C++, so I really need to brush up my STL knowledge. Your videos have a good intermediate level, which is quite rare.
Hmm, was so interesting to see [n=0] as mutable, basically as I understood, you can declare variables in lambda catches block, but because its "mutable" - that variable is not only "catched", its actually created in outside scope of where lambda is runned from? So basically creates new N variable in main() function, right? And its not static, its just normal variable, but not only in lambda, in main too?
Correct, we can create variables in the lambda such that they become 'member variables' in the functor. Still remains private to the scope however -- take a look here: cppinsights.io/lnk?code=I2luY2x1ZGUgPGNzdGRpbz4KCmludCBtYWluKCkKewogICAgY29uc3QgY2hhciBhcnJbMTBdezIsNCw2LDh9OwoKICAJLy8gT2JzZXJ2ZSBpbiBjcHBpbnNpZ2h0cyBob3cgJ24nIGlzIGEgbmV3ICdtZW1iZXIgdmFyaWFibGUnIGluCiAgICAvLyB0aGUgZnVuY3RvciBnZW5lcmF0ZWQuCiAgICBhdXRvIGV4YW1wbGUgPSBbbj0wXSgpIG11dGFibGV7CiAgICAgIAogICAgIAlyZXR1cm4gbisrOyAvLyBhbGxvd2VkIHdpdGggbXV0YWJsZQogICAgfTsKICAKICAJLy9zdGQ6OmNvdXQgPDwgbiA8PCBzdGQ6OmVuZGw7IC8vICduJyBpcyBub3QgYXZhaWxhYmxlIG91dHNpZGUgb2YgY2FwdHVyZQp9&insightsOptions=cpp20&std=cpp20&rev=1.0 (Code here for the above cppinsight) #include int main() { const char arr[10]{2,4,6,8}; // Observe in cppinsights how 'n' is a new 'member variable' in // the functor generated. auto example = [n=0]() mutable{ return n++; // allowed with mutable }; //std::cout