|
Boost : |
From: Eric Niebler (eric_at_[hidden])
Date: 2006-04-18 01:50:08
Peter Dimov wrote:
> Eric Niebler wrote:
>> Peter Dimov wrote:
>
>>> Seeing so many variations of it is a pretty good indication that we
>>> need it in Boost. :-)
>> So you're going to add it? :-)
>
> I can't help but think that even if I did add the above, you wouldn't use it
> because of the virtual destructor,
You're right, because in xpressive alone I use counted_base in no less
than 3 places where the virtual destructor would be needless overhead!
Clearly, it can't be all that uncommon.
and Andreas wouldn't use it because of
> the lack of bool NeedsLocking parameter.
I thought NeedsLocking was reasonable until I noticed that atomic_count
is a typedef for long if BOOST_HAS_THREADS is not defined. That should
be good enough, IMO.
> Anyway, ...
>
>> Tried that. Under certain circumstances, VC7.1 wasn't finding the
>> friend functions. Hence my counted_base_access hack, and the
>> intrusive_ptr_add_ref/release functions at namespace scope.
>
> ... I'm interested in those certain circumstances.
The following program exposes the problem for me with vc7.1, vc8 and gcc
3.4.4. If you comment out the friend functions and uncomment the
global free functions, the problem goes away. I don't understand it --
is some name look-up subtlety at play here?
#include <boost/intrusive_ptr.hpp>
template<typename Derived>
struct counted_base
{
friend void intrusive_ptr_add_ref(counted_base<Derived> *that){}
friend void intrusive_ptr_release(counted_base<Derived> *that){}
};
//template<typename Derived>
//void intrusive_ptr_add_ref(counted_base<Derived> *that){}
//template<typename Derived>
//void intrusive_ptr_release(counted_base<Derived> *that){}
template<typename T>
struct impl
: counted_base<impl<T> >
{
};
template<typename T>
struct outer
{
boost::intrusive_ptr<impl<T> > p;
};
int main()
{
outer<int> impl;
return 0;
}
-- Eric Niebler Boost Consulting www.boost-consulting.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk