My lambdas talk @NWCPP is now online

Lloyd Moore of NWCPP did record some video and post slides of my C++ lambdas talk two days ago. The video and slides (PDF) are now online. You can see Lloyd’s friendly smile in the foreground of the final frame.

The room lighting and layout weren’t great for video recording, but the audio is quite clear and you can refer to the PDF to see everything on the slides in detail.

If your name is Scott Meyers, skip to 41:50. :)

7 thoughts on “My lambdas talk @NWCPP is now online

  1. Herb, I think you might be doing the committee a disservice in that talk by implying polymorphic lambdas didn’t make it because we found the idea of implicit templates too “scary.” It’s my understanding that there was a real technical problem at the time: nobody could figure out how to integrate polymorphic lambdas with concept checking (*). By the time we pulled concepts out of the standard, it was too late to add polymorphic lambdas, and even if it hadn’t been too late I think many of us would have been scared to do it for fear of making it harder to adopt a concepts proposal later.

    (*) I believe I know how to integrate polymorphic lambdas with concept checking now, but at the time most people were convinced there was a real problem.

  2. Yes, Kevin, that’s right. You can implicitly capture “this” by-value, which gives you implicit access to all of the object’s members *without qualification*, yet the “this” pointer can still dangle. Here’s an example:

    // a function object
    struct mul_factory
    {
        mul_factory(int scale) : factor(scale) {}
    
        std::function create()
        {
            return [=](int x){ return x * factor; };
        }
     private:
        int factor;
    };
    
    std::function times3 = mul_factory(3).create();
    int twelve = times3(4);   // BOOM
    

    I think this makes things look deceptively safe, and will be a problem for legions of OO programmers.

  3. Great talk. Vimeo allows me to download this video so that I can watch it offline. That’s great but iss there a way to get a higher resolution version?

  4. Recently there was a discussion on comp.lang.c++.moderated that led to an understanding of a subtle gotcha of ‘capture-by-value’ for lambdas: the gist of it is that ‘capture-by-value’ of a class member does not actually capture the member’s value, but instead captures the value of ‘this’ instead. While this is generally going to make no difference at all, it could make an enormous difference if the programmer is expecting capture-by-value to provide a safe lambda that can outlive the constructing object’s lifetime… because it doesn’t provide that, as ‘this’ is a bare pointer to the object and will become stale if the object is destroyed (or worse, if move semantics are used and the object gets a new set of ‘guts’ without changing addresses).

    If this understanding of capture-by-value in relation to class members is indeed accurate, it seems that it would be worth incorporating into this sort of presentation/talk in order to start getting the word out to users of C++0x/C++11 as early as possible.

  5. After having spent a few years doing Perl OO work, and being familiar with older functional languages, I’m still scratching my head about the new developments of C++…

    When I first started writing perl, I just noted anonymous subs (e.g., perl lambdas) as an interesting quirk, which became totally pervasive in my code in just a few months. Now I’m wondering how I could code without them.

    How could C++ live for so long without them, especially with all the “algorithms” stuff, which is literally screaming for them.

    I guess a large part of that is the noise: there is so much fringe baggage in C++ that’s often, it’s easy to not notice what we don’t have.

    So kuddos to Herb for showing your average C++ programmer what he’s been missing all those years.

  6. Hi Herb. My hair and I thank you for the reference, but we both still really Really REALLY miss polymorphic lambda support in C++0x :-)

    Scott

Comments are closed.