Home | Libraries | People | FAQ | More |
The header
The header contains the following function and class templates:
Function object traits | Used to determine the types of function objects' and
functions' arguments. Eliminate the necessity for |
|
---|---|---|
Negators | Based on section 20.3.5 of the standard. | |
Binders | Based on section 20.3.6 of the standard. | |
Adapters for pointers to functions | Based on section 20.3.7 of the standard. Not required for use with this library since the binders and negators can adapt functions, but may be needed with third party adapters. | |
Adapters for pointers to member functions | Based on section 20.3.8 of the standard. |
Using these adapters should be pretty much the same as using the standard
function object adapters; the only differences are that you need to write
For example, suppose you had a Person class that contained a
class Person { public: void set_name(const std::string &name); // ... };
You could rename a bunch of people in a collection, c, by writing
std::for_each(c.begin(), c.end(), boost::bind2nd(boost::mem_fun_ref(&Person::set_name), "Fred"));
If the standard adapters had been used instead then this code would normally
fail to compile, because
The header and test program have been compiled with the following compilers:
Compiler | Comments |
---|---|
Borland C++Builder 4 Update 2 | No known issues. |
Borland C++ 5.5 | No known issues. |
g++ 2.95.2 | No known issues. |
Microsoft Visual C++ Service Pack 3 | Compiler lacks partial specialisation, so this library
offers little more than is provided by the standard adapters:
|
This library's primary focus is to solve the problem of references to references while maintaining as much compatibility as possible with the standard library. This allows you to use the techniques you read about in books and magazines with many of today's compilers.
In the longer term, even better solutions are likely:
Thanks to John Maddock for suggesting the mechanism that allowed the function objects traits to work correctly. Jens Maurer provided invaluable feedback during the formal review process.
Copyright © 2000 Cadenza New Zealand Ltd. Permission to copy, use, modify, sell and distribute this document is granted provided this copyright notice appears in all copies. This document is provided "as is" without express or implied warranty, and with no claim as to its suitability for any purpose.
Revised 28 June 2000