My talk tomorrow, and a little experimental library

Thanks to everyone who responded to the little puzzle for CppCon that I posted on the weekend. I’ll show a couple of answers in my talk tomorrow at the conference, which will be recorded and should be available on YouTube in a week or so.

My talk will focus primarily on how to use the great std:: facilities we already have in today’s C++, especially scoped lifetime, unique_ptr, and shared_ptr. Those are what you should prefer to use, in that order, to express object lifetimes in C++. In many basic situations, those tools let you express lifetime by construction with complete automation, good performance, and no extra coding work — the bee’s knees!

However, in some advanced situations, using today’s tools does still involve writing some manual code. In my talk I’ll cover how to do that by hand today.

Then at the end of the talk if time allows, I’ll offer some “very experimental” thoughts exploring whether some of that remaining manual code might be automatable, just as we automated single-owner-new/delete with unique_ptr, and automated multi-owner-new/delete-plus-reference-counting with shared_ptr and weak_ptr. To try the ideas out, I wrote a little demo library I call gcpp [GitHub]. You can read about it at that link (but please also read the disclaimers!) and I’ll present parts of it at the end of my talk tomorrow if there’s time. Like any experiment, in the worst case it won’t work out and the ideas will be abandoned; in the best case, my hope is that it may contribute some interesting ideas to develop further.

7 thoughts on “My talk tomorrow, and a little experimental library

  1. Nice library. I wish I could be there to hear the talk.

    On a similar note but more of local-resource cleanup you can also use (hopefully template code will show up properly here)

    “`
    std::shared_ptr cleanupPtr(nullptr, [&](void*) { /* cleanup logic */ });
    “`

    * of course the capture `[&]’ logic should be adjusted according to the lambda-logic’s needs.
    This is just a handy pattern to use RAII and it’s not at all addressing the full scope of what you are talking about but it’s still nice and tidy that I feel is very useful.

  2. So, now that you have a little trove of answers to your puzzle, what are you actually going to do with it? I would be very interested to see some statistics, e.g. how many submissions there were in total, out of which how many correct ones, can the correct solutions be easily classified in a small number of groups according to the ideas behind the approach, etc. It would be a shame to just let all this code go to /dev/null or whatever is that you have instead of it on Windows ;-)

  3. @AC: I didn’t receive all the solutions, but here’s what I mentioned in the talk… I’m told there were over 100 solutions submitted. I asked them to send me just the ones that passed the four test cases; about 10 solutions met that bar. Of those, half used weak_ptr which was unnecessary to the problem so I didn’t look at them closely further once I saw that. The remaining 5 were correct solutions, and there were 3 prizes so I picked the three I liked the most (and confirmed with the submitters that they were physically at CppCon) — one because it explicitly documented using a local stack approach, one because it used a standard algorithm, and one because it had a very funny (to me) pun to name the “mark” function of the mark-and-sweep algorithm.

  4. @SH: Thank you very much for the really curious details, the only thing I could wish for now would be to have a look at the correct solutions, maybe you could be so kind as to e.g. dump them in a gist? Looking forward to watching your talk on YouTube! … and thanks for the puzzle, it was an interesting one :-)

  5. @AC: I don’t think we asked for people’s permission to post their code, but I presented my solution in the talk and there’s working code in test_graph.cpp in the gcpp repo if you want to take a look. Thanks again to everyone who participated, it was fun (and sometimes punny).

Comments are closed.