Listing 3 IDisposable helper functions from .netSTL
/* ///////////////////////////////////////////////////////////// * ... * * Extract from dotnetstl_dispose_functions.h * * Copyright (C) 2003, Synesis Software Pty Ltd. * (Licensed under the Synesis Software Standard Source License: * http://www.synesis.com.au/licenses/ssssl.html) * * ... * ////////////////////////////////////////////////////////// */ namespace dotnetstl { /// Disposes the managed type, and resets the pointer template <ds_typename_param_k T> inline void dispose_set_null(T *&pt) { if(0 != pt) { System::IDisposable *disposable = pt; disposable->Dispose(); pt = 0; } } /// Disposes all the items in a container template <ds_typename_param_k C> inline void dispose_contents(C *pc) { for(int i = 0, count = pc->get_Count(); i < count; ++i) { System::IDisposable *o = dynamic_cast<System::IDisposable*>(pc->get_Item(i)); dispose_set_null(o); } } } // namespace dotnetstl