Implementing the pimpl idiom
pimpl stands for pointer to implementation (also known as the Cheshire cat idiom or the compiler firewall idiom) and is an opaque pointer technique that enables the separation of the implementation details from an interface. This has the advantage that it enables changing the implementation without modifying the interface and, therefore, avoiding the need to recompile the code that is using the interface. This has the potential of making libraries using the pimpl idiom on their ABIs backward-compatible with older versions when only implementation details change. In this recipe, we will see how to implement the pimpl idiom using modern C++ features.
The term ABI stands for Application Binary Interface, and refers to the interface between two binary modules. Typically, one such module is a library or operating system, and the other is a program executed by a user.
Getting ready
The reader is expected to be familiar with smart pointers...