Boost logo

Boost :

From: scleary_at_[hidden]
Date: 2002-10-02 07:20:04


OK, here's what I have never understood about this argument: what's wrong
with
  template <typename T>
  class pimpl_base
  {
    private:
      scoped_ptr<T> pimpl_;
    protected:
      T * pimpl() { return pimpl_.get(); }
      const T * pimpl() const { return pimpl_.get(); }
      explicit pimpl_base(T * const npimpl):pimpl_(npimpl) { }
  };

  class MyObjImpl;
  class MyObj: pimpl_base<MyObjImpl>
  {
    ...
  };

the pimpl_base supplies the const-correctness "necessary" for its derived
classes. Each derived class accesses the implementation via "pimpl()->".

        -Steve

> -----Original Message-----
> From: Yitzhak Sapir [mailto:yitzhaks_at_[hidden]]
> Sent: Wednesday, October 02, 2002 9:04 AM
> To: Boost mailing list
> Subject: RE: [boost] [smart_ptr] const-correctness as
> function argument
>
>
> > -----Original Message-----
> > From: David Abrahams [mailto:dave_at_[hidden]]
>
> > Why is everyone barking up this tree instead of using
> > shared_ptr<T const>
> > "as god intended"?
>
> I don't have a problem with shared_ptr as it is, (and in my
> post, I covered reasons for leaving shared_ptr's as they are
> -- I don't support the viewpoint that shared_ptr should have
> two ->/* functions). But I use scoped_ptr's to hold the
> pointers to a private implementation struct. When I do this,
> I don't want to have non-const access to the struct in const
> functions. Having a scoped_ptr<T const> won't help me in
> this regard because I do want non-const access in non-const functions.
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost
>


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