Feeds:
Posts
Comments

Archive for November 16th, 2011

GotW #100 demonstrated the best way to express the Pimpl idiom using only standard C++11 features:

// in header file
class widget {
public:
    widget();
    ~widget();
private:
    class impl;
    unique_ptr<impl> pimpl;
};

// in implementation file
class widget::impl {
    // :::
};

widget::widget() : pimpl{ new impl{ /*...*/ } } { }
widget::~widget() { }                   // or =default

image

Guru Question

Is it possible to make the widget code easier to write by wrapping the Pimpl pattern in some sort of library helper? If so, how?

Try to make the widget code as convenient and concise as possible to write, with any compiler-generated semantics either correct by default or producing compile-time errors if the widget author forgets to write them.

 

[Update: Removed move operations from the basic pattern. Since not all Pimpl’d types need to be move-aware, it’s not really part of the core pattern.]

Read Full Post »

GotW #100: Solution

image_thumb[3]

The solution to GotW #100 is now live.

Read Full Post »

Follow

Get every new post delivered to your Inbox.

Join 2,112 other followers