I helped organize a talk from Dr. Bjarne Stroustrup in Austin on September 19, 2012. It was a presentation he’s apparently given in some form or another elsewhere, but I had not seen the slides before.
Much of it wasn’t new material for me. I am already familiar with the tenets of “Modern C++”, but he introduced them lucidly for people unfamiliar with concepts like
unique_ptr. I’d also seen his article about type-safety in SI units from IEEE Spectrum.
(Note: What did surprise me was a graph of an experiment he did with the performance of vector vs. list. It also challenged many people’s assumptions about at what size a list would crossover to being faster. The task would seem to benefit substantially from being able to do arbitrary insertions quickly. But it looks like the three most important things in performance are starting to mirror the three most important things in real-estate: Locality, Locality, Locality! :-P)
We didn’t record the talk. It would have been some effort to arrange with the venue, and he told us in advance it would be similar to talks he’s given elsewhere that were online. Yet I should have had the prescience to record the Q&A!
In any case, I did manage to ask him about an issue that had been on my mind for a while:
Do you personally feel that it’s good practice to use
unique_ptr as a way of following the “hot potato” of deletion responsibility on an object, while extracting the raw pointer and passing it into other code? Or should
unique_ptr live up to its name and always be truly “unique”…the only handle to the pointed-to-object in the system?
In the past, I’ve not really been able to get a consistent view from people on this. So I figured there wasn’t a much better person to ask for an authoritative answer!
He had more moments of pause in answering this than the other questions. He prefaced by saying that he didn’t really think there was enough experience with the issue to really establish what “good” and “bad” practice was going to be in the matter. But he said he could offer his “current opinion”.
That opinion was that it was fine IF the holder of the
unique_ptr could guarantee that all of the routines that were passed the extracted pointers were finished before the
unique_ptr was moved to be under the control of someone else.
So that’s “from the horse’s mouth” as of September 19, 2012. Off the top of my head, I do remember a couple of other questions…