FBB::for_each(3) Extensions to the STL for_each function template

SYNOPSIS

#include <bobcat/foreach>

DESCRIPTION

The FBB::for_each function templates extend the STL for_each function template allowing its use in many often occurring situations.

The STL for_each function template requires a pair of iterators preventing its use in situations where an action should be performed a number of times using a plain, non-dereferenceable variable rather than an iterator. Furthermore, the STL template requires the use of either a classless or static class member function or a function object. In situations in which a class member is called a number of times the STL template function cannot easily be used.

The FBB::for_each function template was designed to allow the use of the for_each algorithm in the abovementioned situations. It cannot be used to pass a `local function context' to the function performing the action and it cannot be used to call a function a number of times. In the former case the FBB::FnWrap1c and FBB::FnWrap2c classes can be used; in the latter case the repeat(3bobcat) function templates can be used.

All FBB::for_each template functions are defined inline, allowing the compiler to `optimize away' the for_each function call itself.

Since some of the FBB::for_each function templates use the same number of parameters as the stl::for_each function templates the explicit use of the FBB namespace will often be required in situations where both function templates are made available to the compiler.

NAMESPACE

FBB
All constructors, members, operators and manipulators, mentioned in this man-page, are defined in the namespace FBB.

INHERITS FROM

-

OVERLOADED FUNCTIONS

In the following description several template type parameters are used. They are:
  • Iter represents an iterator type;
  • Function represents a pointer to a classless or static class member function or to a function object;
  • Class represents a class type;
  • Member represents a pointer to a Class member function expecting a (reference to a) derefenced Iter object or an argument of the same type as the first for_each parameter.
  • void for_each(Iter begin, Iter end, Function &fun):
    fun is called end - begin times, passing begin or *begin with begin iterating towards end to fun. If begin and end are class- or pointer type variables *begin is passed to fun otherwise begin is passed to fun.
  • void for_each(Iter begin, Iter end, Class &object, Member member):
    object.*member is called end - begin times, passing begin or *begin with begin iterating towards end to object.*member. If begin and end are class- or pointer type variables *begin is passed to fun otherwise begin is passed to fun.
  • void for_each(Iter begin, Iter end, Class *object, Member member):
    object->*member is called end - begin times, passing begin or *begin with begin iterating towards end to object->*member. If begin and end are class- or pointer type variables *begin is passed to fun otherwise begin is passed to fun. Class and Member may also be defined as const objects.

EXAMPLES

Assume a class CGIFSA defines the following inline function, using the array bool d_escape[] and the variable bool d_setEscape:
    inline void CGIFSA::setEscape(size_t idx)
    {
        d_escape[idx] = d_setEscape;
    }
        
To set a series of d_escape elements to d_setEscape a member function of the class CGIFSA may use the following code (with size_t begin, end):
    if (begin <= end)
        for_each(begin, end + 1, this, &CGIFSA::setEscape);
        

FILES

bobcat/foreach - defines the template functions

BUGS

Note that the for_each algorithms iterate until begin equals end; hence the test for begin <= end in the above example.

DISTRIBUTION FILES

  • bobcat_2.08.01-x.dsc: detached signature;
  • bobcat_2.08.01-x.tar.gz: source archive;
  • bobcat_2.08.01-x_i386.changes: change log;
  • libbobcat1_2.08.01-x_*.deb: debian package holding the libraries;
  • libbobcat1-dev_2.08.01-x_*.deb: debian package holding the libraries, headers and manual pages;
  • http://sourceforge.net/projects/bobcat: public archive location;

BOBCAT

Bobcat is an acronym of `Brokken's Own Base Classes And Templates'.

COPYRIGHT

This is free software, distributed under the terms of the GNU General Public License (GPL).

AUTHOR

Frank B. Brokken ([email protected]).