
On Thu, Jun 9, 2016 at 5:19 AM, Rainer Deyke
On 08.06.2016 23:57, Emil Dotchevski wrote:
On Wed, Jun 8, 2016 at 2:29 PM Rainer Deyke
wrote: 3. I want a class to have value semantics, but use a copy-on-write
implementation behind the scenes.
Pimpl is not about semantics, it's about reducing physical coupling. It's not about the pointer pointing at the private implementation object (which, being private, is an implementation detail anyway), it's about the private implementation *type* being left incomplete.
Pimpl is a technique where the implementation of a class is moved to a separate implementation class (the "impl"), to which the interface class maintains a pointer (the "p").
The "p" stands for "private" not for pointer. The defining property of the pimpl idiom is that the private implementation type is left incomplete in the interface: the pointer is opaque. For example, if you implement copy-on-write using a pointer to a type that is defined in the interface, you're not using pimpl. So, logical design (semantics), including copy semantics, is orthogonal to pimpl. Emil