Binding Reference Types
Callable objects that take parameters by-reference can be problematic when those arguments are bound. rwBind() creates a copy of the parameter specified, essentially negating the by-reference semantics of the original object. In order to avoid this, the utility function rwRef() can be used to create an object that will hold the reference and maintain that relationship across copies. This allows a reference to be bound and stored in the binder object created by rwBind().
For example, if a function returns an
RWCString through a by-reference argument, this argument can be specified via
rwBind() as:
void function1(RWCString& out);
RWCString result;
RWTFunctor<void()> functor1 = rwBind(function1, rwRef(result));
When functor1 is invoked, function1 will be invoked with a reference to result. Any changes to result will be visible once the functor invocation has completed.
NOTE: Note: Since the RWTFunctor holds a reference to the object, it is the responsibility of the user to ensure that the lifetime of the referenced object is longer than the lifetime of the binder object. Otherwise, undefined behavior will result if the binder object is invoked.