Function Pointer Adapters

The header functional.hpp
provides enhanced versions of both the function pointer adapters from the
C++ Standard Library (§20.3.7):

pointer_to_unary_function

pointer_to_binary_function

As well as the corresponding helper function template:

ptr_fun

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.

Usage

If you need to use these adapters, usage is identical to the standard
function pointer adapters. For example,

Note that the argument to operator() is exactly the same type
as the argument to the wrapped function. If this is a value type, the
argument will be passed by value and copied twice.
pointer_to_binary_function has a similar problem.

However, if we were to try and eliminate this inefficiency by instead
declaring the argument as const Arg&, then if Arg were a
reference type, we would have a reference to a reference, which is
currently illegal (but see C++ core
language issue number 106)

So the way in which we want to declare the argument for
operator() depends on whether or not the wrapped function's
argument is a reference. If it is a reference, we want to declare it simply
as Arg; if it is a value we want to declare it as
const Arg&.

The Boost call_traits class
template contains a param_type typedef, which uses partial
specialisation to make precisely this decision. By declaring the
operator() as

Result operator()(typename call_traits<Arg>::param_type x) const

we achieve the desired result - we improve efficiency without generating
references to references.

Limitations

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.