This document is for a version of USD that is under development. See this page for the current release.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
TfDeleter Struct Reference

Function object for deleting any pointer. More...

#include <tf.h>

Public Member Functions

template<class T >
void operator() (T *t) const
 
template<class T1 , class T2 >
void operator() (std::pair< T1, T2 * > p) const
 

Detailed Description

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

for (list<Otter*>::iterator i = otters.begin(); i != otters.end(); ++i)
delete *i;

you can use TfDeleter and simply write

#include <algorithm>
for_each(otters.begin(), otters.end(), TfDeleter());
Function object for deleting any pointer.
Definition: tf.h:98
Note
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.

Definition at line 98 of file tf.h.

Member Function Documentation

◆ operator()() [1/2]

void operator() ( std::pair< T1, T2 * >  p) const
inline

Definition at line 105 of file tf.h.

◆ operator()() [2/2]

void operator() ( T *  t) const
inline

Definition at line 100 of file tf.h.


The documentation for this struct was generated from the following file: