Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
Threads Module User's Guide

8.2 Constructing Functors

To create a functor:

The simplest way to do this is to bind the callable object handle when it is being constructed.

Example 66 shows the minimal code required for building and using a functor.

Example 66: Creating and using a functor

8.2.1 Analyzing Functor Requirements

The type of functor you build depends on the interface you want to expose. Just as with defining a function interface, two key questions need to be answered:

RWTFunctor is a template class with a single template type that encapsulates this information. The template type specifies a function type of the form:

Where <return type> is the type that the functor will return, and <arg type 1>, <arg type 2>, …, <arg type N> are the types of the arguments that the functor will take. For example, if you want to declare a functor that takes no arguments and returns void, the declaration of that functor would be:

Likewise, to declare a functor that takes a double and an int as arguments and returns an int, the declaration would be:

Just as with a normal function, the types in an RWTFunctor's signature can be qualified. For example, if you wanted to declare an RWTFunctor that takes a const RWCString& argument, the declaration would be:

8.2.2 Copying and Assigning Functors

Because functors use the handle-body idiom, copying functors follows the general rules discussed in Section 7.3.1.4, "Handle-Body Mechanics." When a handle class instance is copy-constructed from another handle class instance, the new handle is bound to the same body instance, if any, pointed to by the other handle.

Similarly, assigning one handle to another causes the left-hand instance to detach from its current representation, if any, and then binds it to the same body instance, if any, pointed-to by the right-hand instance.



Previous fileTop of DocumentContentsNo linkNext file

Copyright © Rogue Wave Software, Inc. All Rights Reserved.

The Rogue Wave name and logo, and SourcePro, are registered trademarks of Rogue Wave Software. All other trademarks are the property of their respective owners.
Provide feedback to Rogue Wave about its documentation.