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:
>
> https://github.com/sean-/Boost.Examples/tree/master/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/pimpl_example_pointer_impl.cc:35). 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;

Best,
Vicente

--
View this message in context: http://boost.2283326.n4.nabble.com/pre-review-Pimpl-submission-in-the-review-queue-tp3545794p3548306.html
Sent from the Boost - Dev mailing list archive at Nabble.com.

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