apply() Functions
To efficiently examine the members of a Smalltalk-like collection, use the member function apply():
 
virtual void apply(RWapplyCollectable ap, void* x);
The first argument, RWapplyCollectable, is a typedef:
 
typedef void (*RWapplyCollectable)(RWCollectable*, void*);
In other words, RWapplyCollectable is a pointer to a function with prototype:
 
void yourApplyFunction(RWCollectable* item, void* x)
where yourApplyFunction is the name of the function. You must supply this function. It will be called for each item in the collection, in whatever order is appropriate for the collection, and passed as a pointer to the item as its first argument. You must be careful that you cast the pointer item to the proper derived class. The second argument x is passed through from the call to apply(), and is available for your use. For example, you could use it to hold a handle to a window on which the object is to be drawn.
The apply-functions generally employ the most efficient method for examining all members of the collection. This is their great advantage. Their disadvantage is that they are slightly clumsy to use, requiring you to supply a separate function. The functional equivalent to apply() in the Smalltalk world is do. It takes just one argument: a piece of code to be evaluated for each item in the collection.