Whenever a class template's parameter is a reference the compiler
can't distinguish between member functions overloading tt(const)
and non-tt(const) references. Here is an example of a program that won't
compile:
        verb(
    template <typename T>
    class Wrap
    {
        public:
            Wrap(T const &tr);
            Wrap(T &tr);
    };

    int main()
    {
        int i;
        Wrap<int &> wrap(i);
    }
        )
 and the compiler generates an error message like
    hi(Class(T&) cannot be overloaded with Class(T const&))
        verb(
    'Wrap<T>::Wrap(T&) [with T = int&]' cannot be overloaded
    with 'Wrap<T>::Wrap(const T&) [with T = int&]'
        )

Earlier, in section ref(ADAPTABLEFUN) a program was shown using a support
function having signature
        verb(
    int stringcasecmp(string lhs, string rhs)
        )
    In that section it was noted that this function did introduce
inefficiency, but that an improved signature, using tt(string const &)
parameters fails to compile. With a function declaring a tt(string const &)
parameter tt(std::bind2nd) (cf. section ref(FUNADAPT)) generates an error like
the one mentioned here. Following the call
        verb(
    auto pos = find_if(
                    v1.begin(), v1.end(),
                    not1( bind2nd(ptr_fun(stringcasecmp), target) )
               );
        )
 that was used in section ref(ADAPTABLEFUN) as well as the definition of
tt(bind2nd) (usually found in the system header file ti(binders.h)) we
encounter the following series of instantiated templates:
    itemization(
    it() First, tt(ptr_fun) was instantiated, receiving tt(stringcasecmp). The
function template tt(ptr_fun) returns a tt(pointer_to_binary_function), for
which its tt(first_argument_type) and nl()
    tt(second_argument_type) are determined as tt(string const &) if
tt(stringcasecmp) defines tt(string const &) parameters;
    it() Next, the tt(pointer_to_binary_function) object is passed to
tt(bind2nd). As you may have guessed, we're already on dangerous grounds as
tt(pointer_to_binary_function) is a class template defining reference template
type parameters;
    it() The tt(bind2nd) function template merely creates and returns a
tt(binder2nd) object, initializing it with the tt(pointer_to_binary_function)
object and the type of the second parameter of tt(stringcasecmp) (which can be
ignored in the current discussion);
    it() The tt(binder2nd) class template object is a functor defining two
overloaded function operators (using declarations and simplified type names to
ease focussing on the essence):
        verb(
result_type operator()(first_argument_type const &x) const;
result_type operator()(first_argument_type &x) const;
        )
    As tt(first_argument_type) is a template type parameter deducted to be
tt(string const &) we have overloaded functions using reference parameters and
a template type parameter which itself is a reference parameter. As a
consequence the `tt(cannot be overloaded)' error message results and
tt(stringcasecmp) cannot be defined as a function having tt(string const &)
parameters.
    )

Before the arrival of the C++11 standard this problem could not elegantly be
solved, as pre-C++11 versions of bf(C++) did not offer em(perfect
forwarding). The solution requires a reformulation of tt(bind2nd) and
tt(binder2nd), exploiting
    hi(bind2nd: perfect forwarding)
    features offered by perfect forwarding. Other adaptors defined by the STL
may require comparable reformulations. The modifications required for
tt(bind2nd) and tt(binder2nd) are covered here; it's up to the reader to
implement such modifications for other adaptors when appropriate.

    tt(std::bind2nd) is rewritten here as tt(Bind2nd). It's actually a copy of
tt(bind2nd), but this time creating tt(Binder2nd) rather than
tt(binder2nd). As the (non-configurable) venom is in tt(bind2nd)'s
tt(binder2nd)  call an alternative for tt(bind2nd) is needed to avoid calling
tt(binder2nd). Alternative approaches are also possible. A class template
specialization for tt(binder2nd) could be developed expecting a particular
class which is a wrapper around tt(pointer_to_binary_function). It wouldn't
make much of a difference, as in that case tt(ptr_fun) would have to be
rewritten as well.

So we stick to tt(Bind2nd) having the following obvious implementation (all
functions defined in-class to save some space):
        verbinclude(//BIND2ND examples/ptrfun.cc)
    The meat of the solution is of course in tt(Binder2nd), now using perfect
forwarding. There is now only one function operator member (tt(operator()))
which is now defined as a function template, using the perfect forwarding
incantation. Its body forwards the arguments that were actually passed to the
function call operator em(as well as) tt(Binder2nd)'s (fixed) second argument
to the `operation', which is tt(stringcasecmp). Please note that the forwarded
arguments can very well be followed by additional arguments (here:
tt(d_arg2)). In tt(Binder2nd)'s implementation there's no guarantee that
there will actually only be one perfectly forwarded argument. Although such a
guarantee could easily be built-in (cf. section ref(TEMPLIST)) it really isn't
required as the compiler detects whether there are indeed two arguments
bing passed to tt(stringcasecmp), generating an error message if not. Here is
tt(Binder2nd)'s implementation:
        verbinclude(//BINDER2ND examples/ptrfun.cc)
    The program shown in section ref(ADAPTABLEFUN) remains unaltered but for
the use of tt(bind2nd), which now becomes tt(Bind2nd):
        verb(
    ...
    auto pos = find_if(
                    v1.begin(), v1.end(),
                    not1( Bind2nd(ptr_fun(stringicmp), target) )
               );
        )
    The two programs produce identical output, but the program developed here
is a lot more efficient than the one developed originally, in section
ref(ADAPTABLEFUN).
