Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2002-04-19 09:04:16


From: "Phil Nash" <phil.nash.lists_at_[hidden]>
> Certainly I am in violent agreement that smart_resource like capabilities
> should be made available somewhere (so SmartPtr capabilities applied to
non
> pointers).

Take a look:

#include <boost/shared_ptr.hpp>
#include <iostream>

typedef int HANDLE;

HANDLE CreateHandle()
{
 return 5;
}

void CloseHandle(HANDLE h)
{
 std::cout << "CloseHandle(" << h << ")\n";
}

class shared_handle
{
public:

 explicit shared_handle(HANDLE h): h_(h), c_(h, CloseHandle)
 {
 }

 HANDLE get() const
 {
  return h_;
 }

private:

 HANDLE h_;
 boost::detail::shared_count c_;
};

int main()
{
 shared_handle h(CreateHandle());
 shared_handle h2(h);
}


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