|
Boost : |
Subject: Re: [boost] [Smart Pointers]
From: Arpan Sen (arpansen_at_[hidden])
Date: 2012-12-09 07:04:01
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