Search code examples
c++templatespimpl-idiom

Is there any advantage to the pimpl idiom with a templated class?


It is my understanding that the primary benefit of the pimpl idiom is to hide the data members in the implementation file instead of the header. However, templates need to be fully defined in the header in order for the compiler to instantiate them on demand. In this case, is there any advantage to using the pimpl idiom for a templated class?


Solution

  • While the pimpl idiom doesn't really hide anything when used in a templated class, it does allow you to easily write non-throwing swaps (although with C++11 move semantics this is less of a concern).