FBB::FnWrap2(3) STL binary argument wrapper template class

SYNOPSIS

#include <bobcat/fnwrap2>

DESCRIPTION

The FBB::FnWrap2 class is a configurable binary 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 FBB::FnWrap2 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::FnWrap2 template class has the following template parameters:

  • Type1: the type of the first argument passed to FBB::FnWrap2's operator()() function. Specify the type as the type of the first parameter of the function whose address is passed to the constructor (i.e., specify a plain value or a (const) pointer or reference).
  • Type2: the type of the second argument passed to FBB::FnWrap2's operator()() function. Specify the type as the type of the second 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::FnWrap2 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::FnWrap2 object may be used as a Unary Predicate. Alternatively, pointers or references may be specified as return values.

NAMESPACE

FBB

INHERITS FROM

-

CONSTRUCTOR

  • FnWrap2<Type1, Type2 [, Returntype = void]>(ReturnType (*fun)(Type1, Type2)):

    This constructor expects one argument: the address of a function to call from within its operator()() member. The function receives FBB::FnWrap2::operator()()'s arguments as its arguments. When using (STL) generic algorithms, the template parameter types Type1 and Type2 are the types to which iterators eventually point.

OVERLOADED OPERATOR

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

  • ReturnType operator()(Type1 param, Type2 param) const:
    This function is called by the generic algorithms, receiving the dereferenced iterators that are managed by generic algorithms as its arguments (e.g., the iterator points to modifiable Type1 and Type2 objects).

TYPEDEFS

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

  • first_argument_type:
    , a synonym for the basic type specified with the Type1 template parameter. E.g., if Type1 is specified as std::string const * then first_argument_type will be std::string;
  • second_argument_type:
    , a synonym for the basic type specified with the Type2 template parameter.
  • result_type:
    , a synonym for the basic type specified with the ReturnType template parameter.

EXAMPLES

    #include <algorithm>
    #include <iostream>
    #include <vector>
    #include <string>
    #include <functional>
    
    #include <bobcat/fnwrap2>
    
    using namespace std;
    using namespace FBB;
    
    bool cmp(string &actual, string const &target)
    {
        cout << "Saw " << actual << endl;
    
        bool ret = actual == target;
        actual += ".";
        return ret;
    }
    
    class X
    {
        public:
            static bool cmp(string const &actual, string const &target)
            {
                cout << "Saw " << actual << endl;
                return actual == target;
            }
    };
    
    int main(int argc, char **argv)
    {
        vector<string> vs(argv, argv + argc);
    
        find_if(
            vs.begin(), vs.end(),
            bind2nd(
                FnWrap2<string &, string const &, bool>(&cmp), 
                string("hello")
            )
        );
    
        cout << endl;
    
        find_if(
            vs.begin(), vs.end(),
            bind2nd(
                FnWrap2<string const &, string const &, bool>(&X::cmp), 
                string("hello")
            )
        );
    }
        
After compilation and linking, the program could be called as follows:
    a.out one two hello three hello four
        

FILES

bobcat/fnwrap2 - defines the class interface

BUGS

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

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