Hides implementation details from public headers (static PIMPL). More...
#include <OpaqueObject.h>
Public Types | |
using | Object = typename Definition::Object |
Public Member Functions | |
OpaqueObject (OpaqueObject &&other) | |
OpaqueObject & | operator= (OpaqueObject &&other) |
OpaqueObject (const OpaqueObject &)=delete | |
OpaqueObject & | operator= (const OpaqueObject &)=delete |
Object & | get () |
const Object & | get () const |
Hides implementation details from public headers (static PIMPL).
Opaque object avoids the heap allocation that often comes with PIMPL, allowing to hide OS specific details from public headers. User declares size in bytes of a struct in the header but the structure can be defined in an implementation .cpp file. Choosing a size that is too small will generate a static_assert
that contains in the error message the minimum size to use. Up to 4 functions will need to be defined to avoid linker errors (construct
, destruct
, moveConstruct
, moveAssign
). These functions are meant to be defined in a .cpp
file that will know how to construct Object, as it can see its definition.
Definition | Pass in a custom Definition declaring Sizes and alignment on different platforms |
Example: