|
Boost : |
From: Peter Dimov (pdimov_at_[hidden])
Date: 2001-07-07 06:21:22
Do you think that shared_ptr should acquire an additional template parameter
that specifies the reference count type? I.e.
shared_ptr<class T, class C = long>
This will obviously help in making a thread-safe variant - I'll simply pass
my_win32_atomic_counter as a second argument.
The requirements on C would be
* C::C(<underlying-integer-type>)
* void C::operator++();
* <underlying-integer-type> C::operator--(); // note by-value return
supporting usage like
pc = new C(1)
++*pc
if(--*pc == 0)
and a possible implementation using
InterlockedIncrement/InterlockedDecrement under Win32.
The downside of this change is that this mandates to some extent a reference
counted implementation; of course this is moot for shared_ptr as currently
specified because of shared_ptr::use_count (I don't think that it's allowed
to not be O(1)).
And while we're on the shared_ptr subject... std::less<shared_ptr> vs
operator< ? :-) (std::less can't be specialized on MSVC etc.)
-- Peter Dimov Multi Media Ltd.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk