Boost logo

Boost :

Subject: Re: [boost] [Smart Pointers]
From: Rahul Sr (srivasrrahul_at_[hidden])
Date: 2012-12-09 08:41:01


Thanks for input it does serve me well for some of the cases (where a
single copy is required).
However I face similar problem for shared_ptr as well.
When ref count is 0 it will only call delete. Is there a way I can add
mine?

Regards,
Rahul

On Sun, Dec 9, 2012 at 5:34 PM, Arpan Sen <arpansen_at_[hidden]> wrote:

> why not just use unique_ptr with custom deleter function?
>
> On Sun, Dec 9, 2012 at 9:02 AM, Rahul Sr <srivasrrahul_at_[hidden]> wrote:
>
>> Hi All,
>> This is my first post though so please bear with my sentences.
>>
>> I have used scoped_ptr but this is too tied with new/delete semantics i.e.
>> can't use it with pointers which gets allocated from specialized memory
>> area.
>>
>> class AManager
>> {
>> public:
>> A * allocate();
>> void deallocate(A * p);
>> };
>>
>> class A
>> {
>> .....
>> };
>>
>> This specially happens when I use scoped pointer for C like
>> pointers/allocator:
>>
>>
>> Can I modify scoped pointer to have release semantics which is user
>> defined:
>>
>> template<typename T>
>> class DefaultReleasePolicy
>> {
>> static void releaseA(T * p)
>> {
>> delete p;
>> }
>> };
>>
>> class ReleaseAPolicy
>> {
>> static void releaseA(A * p)
>> {
>> AManager::getInstance()->deallocate(p);
>> }
>> };
>>
>> template<typename T,typemame ReleasePolicy = DefaultReleasePolicy<T> >
>> class ScopedPtrModified
>> {
>> ~ScopedPtrModified()
>> {
>> ReleasePolicy::release(m_ptr);
>>
>> }
>> };
>>
>>
>> Is this fine? Let me know your thoughts.
>>
>> Regards,
>> Rahul
>>
>> _______________________________________________
>> Unsubscribe & other changes:
>> http://lists.boost.org/mailman/listinfo.cgi/boost
>>
>
>
>
> --
> Regards,
> Arpan
>
> -----------------------------------------------------------------------------------------------------------------
> Reality is merely an illusion, albeit a very persistent one.
>


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