Next

Chapter 1. Pimpl C++11

Vladimir Batov

Distributed under the Boost Software License, Version 1.0 (http://www.boost.org/LICENSE_1_0.txt).

Table of Contents

Introduction
The Basics
Easy Pimpl with Shared-Ownership Properties
Pimpl with Exclusive-Ownership Properties
Behind the Interface
Construction and impl_ptr::null()
Customization
In-Place-Implementation Policy
Applications
Delegating Constructors
Lazy-Instantiation Optimization
Singleton
Extendible Unique-Entry Collection
Non-Extendible Unique-Entry Collection
Internal (Implementation-Only) Run-Time Polymorphism
Run-Time Polymorphic Class Hierarchy
Reference
Header <detail/copied.hpp>
Header <detail/inplace.hpp>
Header <detail/shared.hpp>
Header <detail/unique.hpp>
Header <impl_ptr.hpp>
Bibliography
Acknowledgements
Index
[Note] Note

This documentation is based on the article ([1]) originally published in the C/C++ Users Journal.

[Important] Important

This library is not part of the Boost C++ Libraries collection. An endorsement/review request has been submitted. The documentation has been adjusted for the purpose. I apologize for any potential confusion and inconvenience.

In the domain of commercial large-scale software development the following design principles become important:

  • modularity, separation of concerns ([8], [9]),
  • implementation hiding,
  • minimization of compilation and component dependencies,
  • consistent and recognizable implementation and deployment patterns,
  • multi-platform support.

The Pimpl idiom can help great deal achieving these goals. It is a simple yet robust programming technique to minimize coupling via

  • the separation of public interface and private implementation and then
  • implementation hiding.

Popularized by Sutter ([2], [3], [11], [12], [13], [14]) under the cheeky Pimpl name (as for "pointer to implementation" and more precisely "pointer to opaque implementation") the technique has been known under various names -- the D-pointer (in Qt), the Cheshire Cat (in [4]), the Handle/Body (in [5] and [6]), the Bridge (in [6]) -- and deployed in C and C++ as far back as at least early eighties ([7]).

Still, on a smaller scale it does not seem to be widely embraced and uniformly deployed. In part that might be due to efficiency considerations (valid or misguided) and potentially due to additional implementation-related overhead associated with the technique.

This header-only library provides a deployment pattern and the supporting infrastructure in an attempt

  • to minimize the deployment and maintenance hassle and the potential for error,
  • to formalize the deployment of the idiom.

Last revised: September 03, 2017 at 23:04:27 GMT


Next