Boost logo

Boost :

Subject: Re: [boost] [pimpl] Some comments
From: Mostafa (mostafa_working_away_at_[hidden])
Date: 2014-06-06 06:12:10


On Thu, 05 Jun 2014 14:21:04 -0700, Andrzej Krzemienski
<akrzemi1_at_[hidden]> wrote:

> It looks from the docs that 'pointer_semantics' implements something
> like a
> flyweight. This is so against value semantics.

Not to sound snarky, but pointer semantics is exactly that, pointer
semantics, I don't expect it to behave like value semantics.

> One of the expectations of
> types returned by value is that changing the original does no affect the
> copy:
> T a = c;
> T b = c;
> zap(a);
> assert(b==c && a!=b);
> Although the author of class Book knows that it is implemented with
> pointer_semantics, the users of the class are likely not to know it, and
> since Book doesn't look like a pointer, they will be expecting value
> semantics, and will be severely punished.

Unless I'm dealing with pimpl'd classes, then I don't hold that
expectation. Granted, it may not be clear from the type name that the type
in question is pimpl'd, but I chalk that up to poor naming and language
flexibility. The same issue can easily arise with the following bare bone
C++ code:

// In some header file.
typedef some_type * widget;
// In some other header file.
widget foo();

When dealing with pimpl'd classes, the expected norm (in my experience)
for making deep copies is to use the clone function.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk