Two years later I understand the situation much better, in the interest of keeping stack overflow answers relevant and up to date here is how I would answer the question today.
The premise of my original question is somewhat flawed. The reason to use the pimpl-idiom is to hide implementation details from the compiler. This is done by storing the implementation via an opaque pointer (pointer to a declared but not defined data type). This can greatly reduce the amount of headers needed by other compilation units which interact with the class and thus speed up compile time. In the case of the template in my question it is required that the type T be fully known at the point of instantiation which in practice requires the the impl's type be fully defined wherever C<ImplType>
is used making this clearly not an example of the pimpl-idiom in the classic sense of the term.
There are other reasons to hold a classes data via a private pointer, for example it allows for easy implementation of no-throw move and swap and is also good if your class needs to fulfill a strong exception guarantee (see copy and swap idiom What is the copy-and-swap idiom?). On the other hand it adds a layer of indirection (often resulting in a cache miss) on every access to the impl and a heap allocation/deallocation upon creation and destruction of the impl. These can be substantial performance penalties, therefore this solution 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.
T
, as well as its interface, must be exposed, because "clients" need to instantiate the template. For example, where do you callnew T()
? You cannot hide that in "cpp" file because it must be in template. So it is not PIMPL. – Mogilev