fnwrap1.3bobcat

Langue: en

Version: 348824 (ubuntu - 24/10/10)

Section: 3 (Bibliothèques de fonctions)

NAME

FBB::FnWrap1 - STL unary argument wrapper template class

SYNOPSIS

#include <bobcat/fnwrap1>

DESCRIPTION

The FBB::FnWrap1 class is a configurable unary argument wrapper template class. Its primary use is in combination with the generic algorithms of the standard template libray.

The callled function itself may be specified as one of the constructor's arguments. It must be a (static member) function. Using a (static member) function has various advantages, especially with the FnWrap?c classes to which a local context can be passed:

o
There is no introduced uncertainty about the const-ness of the callled function, as static member functions do not support a const modifier;
o
The passed function can also be a free (global) function to which a local context is passed;
o
The passed function can be a static member function of the class using the generic algorithm to which the c() object is passed. By passing the calling object in the function's local context, the function may directly access the calling object's members.
o
The passed function can be a static member function of the class whose objects are passed to the function via the generic template function s iterator parameters. In that case the function may directly access the passed object's members.
o
Since no object is involved in calling the static function, no ambiguity can arise as to whether an object reference or an object pointer should be used in calling the function: static (member) functions may be called without using objects.

The FBB::FnWrap1 template class has the following template parameters:

o
Type: the type of the argument passed to FBB::FnWrap1's operator()() function. Specify the type as the type of the parameter of the function whose address is passed to the constructor (i.e., specify a plain value or a (const) pointer or reference).
o
ReturnType: the ReturnType is by default defined as void. By specifying another type, the FBB::FnWrap1 object's operator()() function will return the called function's return value as a value of the specified type. E.g, by specifying a bool ReturnType, the FBB::FnWrap1 object may be used as a Unary Predicate. Alternatively, pointers or references may be specified as return values.

NAMESPACE

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

INHERITS FROM

-

CONSTRUCTOR

o
FnWrap1<Type [, Returntype = void]>(ReturnType (*fun)(Type)):

This constructor expects one argument: the address of a function to call from within its operator()() member. The function receives FBB::FnWrap1::operator()()'s argument as its argument. When using (STL) generic algorithms, the template parameter type Type is the data type to which iterators (as specified in, e.g., std::for_each()) eventually point.

OVERLOADED OPERATOR

In normal situations the following member function will call the function that is passed to FBB::FnWrap1's constructor. See the example below.

o
ReturnType operator()(Type param) const:
This function is called by the generic algorithms, receiving the dereferenced iterator that is managed by generic algorithms as its argument (e.g., the iterator points to modifiable Type objects).

TYPEDEFS

The class defines two types, which are used by generic algorithms:

o
argument_type:
, a synonym for the basic type specified with the Type template parameter. E.g., if Type is specified as std::string const * then argument_type will be std::string;
o
result_type:
, a synonym for the basic type specified with the ReturnType template parameter.

EXAMPLES

 
     #include <algorithm>
     #include <iostream>
     #include <vector>
     #include <string>
     #include <bobcat/fnwrap1>
     
     using namespace std;
     using namespace FBB;
     
     bool cmp(string &actual)    // modifies `actual'
     {
         cout << "Saw " << actual << endl;
         bool ret = actual == "hello";
         actual += ".";
         return ret;
     }
     
     class X
     {
         public:
                                 // merely inspects `actual'
             static bool cmp(string const &actual)
             {
                 cout << "Saw " << actual << endl;
                 return actual == "hello";
             }
     };
     
     int main(int argc, char **argv)
     {
         vector<string> vs(argv, argv + argc);
     
         vector<string>::iterator it;
     
         it = find_if(vs.begin(), vs.end(),
             FnWrap1<string &, bool>(&cmp));
     
         if (it != vs.end())
             cout << "At " << *it << endl;
     
         cout << endl;
     
         it = find_if(vs.begin(), vs.end(),
             FnWrap1<string const &, bool>(&X::cmp));
     
         if (it != vs.end())
             cout << "At " << *it << endl;
     
     }
         
 
After compilation and linking, the program could be called as follows:
 
     a.out one two hello three hello four
         
 

FILES

bobcat/fnwrap1 - defines the class interface

SEE ALSO

bobcat(7), fnwrap(3bobcat), fnwrap1c(3bobcat), fnwrap2(3bobcat), fnwrap2c(3bobcat), foreach(3bobcat), repeat(3bobcat)

BUGS

The fnwrap(3bobcat) function wrapper is easier to use an provides this class's functionality.

DISTRIBUTION FILES

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

BOBCAT

Bobcat is an acronym of `Brokken's Own Base Classes And Templates'. This is free software, distributed under the terms of the GNU General Public License (GPL).

AUTHOR

Frank B. Brokken (f.b.brokken@rug.nl).