Boost logo

Boost :

Subject: Re: [boost] [pre-review] Pimpl submission in the review queue
From: Vicente Botet (vicente.botet_at_[hidden])
Date: 2011-05-24 17:37:22

Sean Chittenden-4 wrote:
> Actually... let me post a quick example that I wrote to both learn and
> quickly teach how to use Pimpl:
> It takes about 60sec-3min for most people to have their "ah ha!" moment
> with that example (those unfamiliar with Pimpl would be wise to check it
> out, imnsho).
> I didn't dive in to the why, but in the implementation it is necessary
> open your namespace after you have defined your private implementation
> (see pimpl/ It would be nice to know why
> this is the case (or if it's a bug).

I guess this is because the implementation must be a specialization of the
class pimpl, which is not in your name space.

An alternative design could be to let you define your implementation class
and use a trait to select the implementation.

namespace org {
namespace example {

struct MyStringImpl {...};

} // namespace example
} // namespace org

template <>
struct pimpl_trait<org::example::String> {
  typedef org::example::String type;

Vladimir, what do you think?

Is the use of (*this)-> in your example really needed?

bool String::append(unsigned char byte) {
  (*this)->str_->append(1, byte);
  return true;

Or does the following work?

bool String::append(unsigned char byte) {
  this->str_->append(1, byte);
  return true;

BTW, if you want to simplify a little bit your example you could use string
str_; instead of string* str;


View this message in context:
Sent from the Boost - Dev mailing list archive at

Boost list run by bdawes at, gregod at, cpdaniel at, john at