![]() |
Function object for deleting any pointer. More...
Public Member Functions | |
| template<class T > | |
| void | operator() (T *t) const |
| template<class T1 , class T2 > | |
| void | operator() (std::pair< T1, T2 * > p) const |
Function object for deleting any pointer.
An STL collection of pointers does not automatically delete each pointer when the collection itself is destroyed. Instead of writing
you can use TfDeleter and simply write
TfDeleter calls the non-array version of delete. Don't use TfDeleter if you allocated your space using new[] (and consider using a vector<> in place of a built-in array). Also, note that you need to put parenthesis after TfDeleter in the call to for_each().Finally, TfDeleter also works for map-like collections. Note that this works as follows: if TfDeleter is handed a datatype of type std::pair<T1,T2*>, then the second element of the pair is deleted, but the first (whether or not it is a pointer) is left alone. In other words, if you give TfDeleter() a pair of pointers, it only deletes the second, but never the first. This is the desired behavior for maps.