Home | Libraries | People | FAQ | More |
The header
As well as the corresponding helper function template:
However, you should not need to use the adapters in conjunction with the adapters in this library due to our use of function object traits. You will however need to use them if your implementation fails to work properly with our traits classes (due to lack if partial specialisation), or if you wish to use a function object adapter from a third party.
If you need to use these adapters, usage is identical to the standard function pointer adapters. For example,
bool bad(std::string foo) { ... } ... std::vector<std::string> c; ... std::vector<std::string>::iterator it = std::find_if(c.begin(), c.end(), std::not1(boost::ptr_fun(bad)));
Note however that this library contains enhanced negators that support function object traits, so the line above could equally be written
std::vector<std::string>::iterator it = std::find_if(c.begin(), c.end(), boost::not1(bad));
The standard defines
template <class Arg, class Result> class pointer_to_unary_function : public unary_function<Arg, Result> { public: explicit pointer_to_unary_function(Result (* f)(Arg)); Result operator()(Arg x) const; };
Note that the argument to
However, if we were to try and eliminate this inefficiency by
instead declaring the argument as
So the way in which we want to declare the argument for
The Boost
Result operator()(typename call_traits<Arg>::param_type x) const
we achieve the desired result - we improve efficiency without generating references to references.
The call traits template used to realise this improvement relies on partial specialisation, so this improvement is only available on compilers that support that feature. With other compilers, the argument passed to the function will always be passed by reference, thus generating the possibility of references to references.
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