NAME
FBB::Wrap1 - STL unary argument wrapper template class
SYNOPSIS
#include <bobcat/wrap1>
DESCRIPTION
The FBB::Wrap1 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 Wrap?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::Wrap1 template class has the following template parameters:
- o
-
Type: the type of the object passed to FBB::Wrap1's operator()() function. Specify a plain type, do not specify a pointer or reference type: if pointers or references are used, it will become obvious later on, as the template will be able to handle (const) references and pointers. Values of primitive types are handled by (and should be defined as) const-reference parameters.
- o
-
ReturnType: the ReturnType is by default defined as void. By specifying another type, the FBB::Wrap1 object's operator()() function will pass the called function's return value as a value of the specified type. E.g, by specifying a bool ReturnType, the FBB::Wrap1 object may be used as a Unary Predicate
NAMESPACE
FBB
All constructors, members, operators and manipulators, mentioned in this man-page, are defined in the namespace FBB.
INHERITS FROM
-
CONSTRUCTORS
- o
-
Wrap1<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::Wrap1::operator()()'s argument as its argument. The template parameter type Type is the data type to which iterators (as specified in, e.g., std::for_each()) eventually point.
- o
-
Wrap1<Type [, Returntype = void]>(ReturnType (*fun)(Type const &)):
This constructor is identical to the first constructor, except for the actual Type parameter that's passed to the function, which is now a Type const &.
- o
-
Wrap1<Type [, Returntype = void]>(ReturnType (*fun)(Type *)):
This constructor is identical to the first constructor, except for the actual Type parameter that's passed to the function, which is now a Type *.
- o
-
Wrap1<Type [, Returntype = void]>(ReturnType (*fun)(Type const *)):
This constructor is identical to the first constructor, except for the actual Type parameter that's passed to the function, which is now a Type const *.
OVERLOADED OPERATORS
In normal situations the following member functions will call the function that is passed to FBB::Wrap1's constructor. See the example below.
- o
-
ReturnType operator()(Type ¶m) const:
This function is called by the generic algorithms, receiving the dereferenced iterator that is managed by the generic algorithm as its argument (so, the iterator points to modifiable Type objects). This operator is used with the first constructor.
- o
-
ReturnType operator()(Type const ¶m) const:
This function is called by the generic algorithms, receiving the dereferenced iterator that is managed by the generic algorithm as its argument (so, the iterator points to immutable Type objects). This operator is used with the second constructor.
- o
-
ReturnType operator()(Type *param) const:
This function is called by the generic algorithms, receiving the dereferenced iterator that is managed by the generic algorithm as its argument (so, the iterator points to pointers to modifiable Type objects). This operator is used with the third constructor.
- o
-
ReturnType operator()(Type const *param) const:
This function is called by the generic algorithms, receiving the dereferenced iterator that is managed by the generic algorithm as its argument (so, the iterator points to pointers to immutable Type objects). This operator is used with the fourth constructor.
TYPEDEFS
The class defines two types, which are used by generic algorithms:
- o
-
argument_type:
, a synonym for Type;
- o
-
result_type:
, a synonym for ReturnType.
EXAMPLES
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <bobcat/wrap1>
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);
find_if(vs.begin(), vs.end(),
Wrap1<string, bool>(&cmp));
cout << endl;
find_if(vs.begin(), vs.end(),
Wrap1<string, bool>(&X::cmp));
}
FILES
bobcat/wrap1 - defines the class interface
SEE ALSO
BUGS
None Reported.
DISTRIBUTION FILES
- o
-
bobcat_1.11.0-x.dsc: detached signature;
- o
-
bobcat_1.11.0-x.tar.gz: source archive;
- o
-
bobcat_1.11.0-x_i386.changes: change log;
- o
-
libbobcat1_1.11.0-x_i386.deb: debian package holding the libraries;
- o
-
libbobcat1-dev_1.11.0-x_i386.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'.
COPYRIGHT
This is free software, distributed under the terms of the GNU General Public License (GPL).
AUTHOR
Frank B. Brokken ([email protected]).