Boost logo

Boost :

From: JOAQUIN LOPEZ MU?Z (joaquin_at_[hidden])
Date: 2005-03-03 17:21:49


----- Mensaje original -----
De: Jonathan Turkanis <technews_at_[hidden]>
Fecha: Jueves, Marzo 3, 2005 9:49 pm
Asunto: [boost] [congif] BOOST_BEFRIEND_TEMPLATE, BOOST_PRIVATE

> 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.

FWIW, I've also been forced to use a similar workaround.

>
> 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
>

BOOST_PRIVATE seems a little to uninformative a name to me.
The macros I'm using are:

BOOST_PRIVATE_IF_MEMBER_TEMPLATE_FRIENDS
BOOST_PROTECTED_IF_MEMBER_TEMPLATE_FRIENDS

(well, I'm using lib-specific variations of these names,
but you get the idea.)

As for your proposal, I like it: there are at least three
libraries that would benefit from it.

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