---
name: "wrap2"
section: "3bobcat"
platform: "linux"
package: "libbobcat1-dev"
version: "1.11.0-1"
release: "Debian 4.0 (Etch)"
platforms: ["linux"]
url: "https://new.carta.tech/wrap2"
---

# wrap2(3bobcat)

STL binary argument wrapper template class

## NAME

FBB::Wrap2 - STL binary argument wrapper template class

## SYNOPSIS

**#include \<bobcat/wrap2\>**\

## DESCRIPTION

The **FBB::Wrap2** 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 **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 **FBB::Wrap2** 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::Wrap2** template class has the following template parameters:

- o

  *Type1*: the type of the first object passed to **FBB::Wrap2**'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 may be handled as const-references.

- o

  *Type2*: the type of the second object passed to **FBB::Wrap2**'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 may be handled as const-references.

- o

  *ReturnType*: the **ReturnType** is by default defined as *void*. By specifying another type, the **FBB::Wrap2** 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::Wrap2** object may be used as a *Binary Predicate*

## NAMESPACE

FBB

## INHERITS FROM

\-

## CONSTRUCTORS

- o

  **Wrap2\<Type1, Type2 \[, Returntype = void\]\>(ReturnType (\*fun)(Type1 &,** **Type2 &))**:\
  \
   This is an example of the form in which the class's constructurs may be called. Each constructor expects one argument: the address of a function to call from within its **operator()()** member. This function itself should expect two arguments.

-

  Both arguments that are passed to the function pointed to by *fun* may be passed as: \
   reference, \
   pointer,\
   const reference, or \
   const pointer. \

-

  Therefore, the class supports  16 different types of constructors. E.g.:

-

  - o

  **Wrap1\<Type1, Typ2 \[, Returntype = void\]\>(ReturnType**  **(\*fun)(Type1 const &, Type2 const &))**:\
  \
   or:

- o

  **Wrap1\<Type1, Typ2 \[, Returntype = void\]\>(ReturnType**  **(\*fun)(Type1 \*, Type2 const &))**:\
  \

## OVERLOADED OPERATORS

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

- o

  **ReturnType operator()(Type1 &param1, Type2 &param2) const**:\
   This function is called by the generic algorithms, receiving the dereferenced iterators that are managed by the generic algorithm as its arguments (so, the iterators point to modifiable *Type1* and *Type2* objects).

-

  There are 16 overloaded versions of this function, one for each of the 4 x 4 combinations of the two parameter types specified for the function whose address is passed to the class's constructor (i.e., each parameter may be specified as reference, pointer, const reference or const pointer).

-

  Some (but not all) overloaded versions are:

- o

  **ReturnType operator()(Type1 const &param1, Type2 \* param2) const**:\
   or

- o

  **ReturnType operator()(Type1 \*param1, Type2 &param2) const**:\

## TYPEDEFS

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

- o

  **first\_argument\_type**:\
   , a synonym for **Type1**;

- o

  **second\_argument\_type**:\
   , a synonym for **Type2**;

- o

  **result\_type**:\
   , a synonym for **ReturnType**.

## EXAMPLES

```
    #include <algorithm>
    #include <iostream>
    #include <vector>
    #include <string>
    #include <functional>
    #include <bobcat/wrap2>
    using namespace std;
    using namespace FBB;
    bool cmp(string &actual, string &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(Wrap2<string, string, bool>(&cmp), string("hello")));
        cout << endl;
        find_if(vs.begin(), vs.end(),
            bind2nd(Wrap2<string, string, bool>(&X::cmp), string("hello")));
    }
```

## FILES

*bobcat/wrap2* - defines the class interface

## SEE ALSO

[**bobcat**(7)](/bobcat/7.md), [**wrap1**(3bobcat)](/wrap1/3bobcat.md), [**wrap1c**(3bobcat)](/wrap1c/3bobcat.md),  [**wrap2c**(3bobcat)](/wrap2c/3bobcat.md)

## 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 (**f.b.brokken@rug.nl**).
