Xavax C++ Library Class Index   FAQ   Overview

Functors

A functor, also called a function object, is an object that acts as a function by overloading operator(). Functors are used within the Xavax C++ Library as callbacks for generic algorithms and containers. For example, an ordered collection must have a means to determine if an element of type T is less than, equal to, or greater than a second element of type T. Therefore, containers that maintain an ordered collection require the user to provide a compare functor that compares two elements.

All standard functors in the Xavax C++ Library are defined as template classes so that type-safe containers can require functors that operate on the specified type. User functors should derive from one of the standard functor classes and implement operator() which is a pure virtual function.

Functor Summary
CompareFunctor<T> Compare two elements of type T.
TraverseFunctor<T> Traverse an element of a container.

Functor Detail

CompareFunctor<T>

int operator()(const T* t1, const T* t2)
Compare two elements of type T. This pure virtual function must be implemented by any derived class.
Parameters:
t1 - the first element to compare.
t2 - the second element to compare.
Returns:
a value less than zero if t1 < t2,
a value greater than zero if t1 > t2, or
a value of zero if t1 == t2.

TraverseFunctor<T>

bool operator()(const T* t)
Traverse an element of type T in a container and return true if the traversal should continue. The behavior of this function is entirely user-defined. This pure virtual function must be implemented by any derived class.
Parameters:
t - the element to traverse.
Returns:
true if the traversal should continue.

Copyright © 2003 Xavax Inc. -- All Rights Reserved