Boost logo

Boost :

Subject: [boost] [Smart Pointers]
From: Rahul Sr (srivasrrahul_at_[hidden])
Date: 2012-12-08 22:32:12


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


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