FBB::FnWrap1(3) STL unary argument wrapper template class


#include <bobcat/fnwrap1>


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:

  • There is no introduced uncertainty about the const-ness of the callled function, as static member functions do not support a const modifier;
  • The passed function can also be a free (global) function to which a local context is passed;
  • 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.
  • 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.
  • 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:

  • 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).
  • 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.


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




  • 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.


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

  • 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).


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

  • 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;
  • result_type:
    , a synonym for the basic type specified with the ReturnType template parameter.


    #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
                                // 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


bobcat/fnwrap1 - defines the class interface


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


  • 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 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).


Frank B. Brokken ([email protected]).