Boost logo

Boost :

From: JOAQUIN LOPEZ MU?Z (joaquin_at_[hidden])
Date: 2005-03-03 19:22:36


----- Mensaje original -----
De: Peter Dimov <pdimov_at_[hidden]>
Fecha: Viernes, Marzo 4, 2005 0:32 am
Asunto: Re: [boost] [congif] BOOST_BEFRIEND_TEMPLATE, BOOST_PRIVATE

> Jonathan Turkanis wrote:
> > Hi,
> >
> > <boost/shared_ptr.hpp> contains the following in the public section
> > of the class definition (reformatted):
> >
> > // Tasteless as this may seem, making all members public
> > // allows member templates to work in the absence of member
> > // template friends. (Matthew Langston)
> >
> > #ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
> >
> > private:
> >
> > template<class Y> friend class shared_ptr;
> > template<class Y> friend class weak_ptr;
> >
> >
> > #endif
> >
> > T * px; // contained pointer
> > detail::shared_count pn; // reference counter
> >
> > This has become a pretty common technique, I believe. I
> certainly use
> > it a lot, at any rate.
> >
> > I'd like to suggest two macros which would allow code like the above
> > to be simplified as follows:
> >
> > BOOST_PRIVATE:
> > BOOST_BEFRIEND_TEMPLATE(shared_ptr, Y, 1)
> > BOOST_BEFRIEND_TEMPLATE(weak_ptr, Y, 1)
> >
> > T * px; // contained pointer
> > detail::shared_count pn; // reference counter
>
> This doesn't look any better to me than the original, sorry. ;-)

Well, I think there are situations were it'd improve readability:

Example 1: previous section was not public

#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
private:

  template<class Y> friend class shared_ptr;
  template<class Y> friend class weak_ptr;
#else
public:
#endif

Example 2: derivation

class Derived:
#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
private
else
public
#endif
Base
{
...
};

Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo


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