Boost logo

Boost :

From: Yitzhak Sapir (yitzhaks_at_[hidden])
Date: 2002-10-02 09:04:57


1) Usually I declare my classes as
class some_class
{
  ...
private:
  class impl;
  boost::scoped_ptr<impl> m_impl;
  ...
};

It seems to me more natural that the implementation class of the class belongs to the class rather than sits outside of it. Using this, it becomes harder to use a pimpl_base. I also think having those two lines is a little clearer than inheriting from pimpl_base (but just a little).

2) I know I can write an adaptor for scoped_ptr to do this (calling it impl_ptr or whatever). I suggested it before, and I'll probably do it soon for myself. This post, I was thinking that since a scoped_ptr is the owner of the data, const functions on the pointer should give const data. Maybe I'm just wrong or missing something :) But since passing scoped_ptr's as an argument may be rare (passing p.get() may be a better option), is there really a need to have a operator->()const (and operator*() const) that returns a non-const T? (Even a rare use-case would suffice for me to convince me it's wrong to have them in scoped_ptr, I was just suggesting something).

> -----Original Message-----
> From: scleary_at_[hidden] [mailto:scleary_at_[hidden]]
> Sent: Wednesday, October 02, 2002 2:20 PM
> To: boost_at_[hidden]
> Subject: RE: [boost] [smart_ptr] const-correctness as
> function argument
>
>
> 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
> >
> _______________________________________________
> 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