Two years later, I understand the situation much better, in the interest of preserving the answers, relevant and relevant, thatโs how I would answer this question today.
The premise of my original question is somewhat flawed. The reason for using pimpl-idiom is to hide implementation details from the compiler. This is done by storing the implementation through an opaque pointer (a pointer to a declared but not defined data type). This can significantly reduce the number of headers needed by other compilers that interact with the class and thereby speed up compilation time. In the case of a template, my question requires that the type T be fully known at the time of creating the instance, which in practice requires that the impl type be fully defined wherever C<ImplType> , which makes this clearly not an example of pimpl -idiom in the classic sense of the word.
There are other reasons for storing class data using a private pointer, for example, it makes it easy to implement move and swap without throwing, and it is also good if your class has to fulfill a strong exception guarantee (see copying and swap idiom What is the copy and swap idiom ? ). On the other hand, it adds a layer of indirection (often leading to a cache miss) with each access to the implant and the allocation / release of the heap when creating and destroying the implication. These can be significant penalties, so this decision should not be considered a silver bullet.
If you can use C ++ 11 then std :: unique_ptr should be used instead of boost :: scoped_ptr.
source share