Boost logo

Boost :

From: Reece Dunn (msclrhd_at_[hidden])
Date: 2003-12-19 15:22:16

How about using a smart pointer-style management system, e.g. (using my
implementation, but adabtable to others like Loki, et. al.):

struct FILEResource
   static void Free( FILE * f )
      ::fclose( f );

   adl::ptr::pointer< FILE *, FILEResource > hFile = ::fopen( "Foo", "w" );
   // ...
   hFile = ::fopen( "Foo2", "w" ); // will close the other file

This would then give additional advantages that sm art pointers provide. If
you want to make it easier to supply the resource function, you could
implement a ptr_fun style helper class:

   adl::ptr::pointer< FILE *, resource< ::fclose > > ...;

NOTE: If there is interest in my smart pointer implementation (based on
Loki, CComPointer, and others), let me know and I'll post it to the files
section. (I am not sure how portable the code is, though).

Reece H Dunn

Tired of 56k? Get a FREE BT Broadband connection

Boost list run by bdawes at, gregod at, cpdaniel at, john at