Re: [boost] [congif] BOOST_BEFRIEND_TEMPLATE, BOOST_PRIVATE

----- Mensaje original ----- De: Jonathan Turkanis <technews@kangaroologic.com> 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

JOAQUIN LOPEZ MU?Z wrote:
De: Jonathan Turkanis
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.
I like it because if you ignore the BOOST_ (and the case) the code looks like it would on a conforming compiler -- you can forget about what happens on a broken compiler.
The macros I'm using are:
BOOST_PRIVATE_IF_MEMBER_TEMPLATE_FRIENDS BOOST_PROTECTED_IF_MEMBER_TEMPLATE_FRIENDS
These would be okay with me. But sometimes I use a macro for specifying the type of derivation, and struct derived_class : BOOST_PRIVATE_IF_MEMBER_TEMPLATE_FRIENDS base_class { }; seems a bit long.
(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.
Thanks.
Joaquín M López Muñoz
Jonathan
participants (2)
-
JOAQUIN LOPEZ MU?Z
-
Jonathan Turkanis