This is great Mathieu, thanks for getting the discussion going. I’m going to mull on this a bit - I’ve probably implemented all of the above :-), but I agree some standardization would be good.
Please don’t use shared_ptr, but unique_ptr instead. There are zero reasons why these classes should escape and be cooperatively shared around. Also, just do Internals(new vtkInternals) instead of .reset().
Why would the class be in a container? Do you have some use case in mind? Note that most containers require a full declaration (for sizeof) which kind of defeats the point.
I think that is slightly orthogonal. The example you point to is not strictly PIMPL. So it shouldn’t’ really be affected by this.
Independently, in your example it’s not clear to me what benefit you get by allocating std::vector on stack. It’s contents are most certainly not on stack. Hence, you could adopt PIMPL there and then std::unique_ptr approach proposed here would work just fine. Note, you don’t have to. The proposal here is not to require PIMPL, but come up with a standard practice should one choose to do so in their VTK classes.
Minor addition on unique_ptr: The C++ Core guidelines recommend to use make_unique() to make unique_ptrs instead of explicit allocation with new (mainly for exception safety - though in this particular case this is probably not relevant).
Alas, that is beyond VTK’s C++ requirement. In any case, VTK is already exception-ignorant, so any such exception will surely leave all kinds of other rubble in its wake; a bit of leaked memory is the least of anyone’s worries at that point. But, once we have C++14, yes make_unique all the way.
That’s not PIMPL at all because it is in a public header.
ref: PImpl - cppreference.com "Pointer to implementation" or "pImpl" is a C++ programming technique[1] that removes implementation details of a class from its object representation by placing them in a separate class, accessed through an opaque pointer:
You’re not doing that. You are placing the details of the class in the header.