Annex D (normative) Compatibility features [depr]

D.8 Function objects [depr.function.objects]

D.8.1 Base [depr.base]

The class templates unary_function and binary_function are deprecated. A program shall not declare specializations of these templates.

namespace std {
  template <class Arg, class Result>
  struct unary_function {
    typedef Arg    argument_type;
    typedef Result result_type;
  };
}

namespace std {
  template <class Arg1, class Arg2, class Result>
  struct binary_function {
    typedef Arg1   first_argument_type;
    typedef Arg2   second_argument_type;
    typedef Result result_type;
  };
}

D.8.2 Function adaptors [depr.adaptors]

The adaptors ptr_fun, mem_fun, mem_fun_ref, and their corresponding return types are deprecated. [ Note: The function template bind [func.bind] provides a better solution.  — end note ]

D.8.2.1 Adaptors for pointers to functions [depr.function.pointer.adaptors]

To allow pointers to (unary and binary) functions to work with function adaptors the library provides:

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; };

operator() returns f(x).

template <class Arg, class Result> pointer_to_unary_function<Arg, Result> ptr_fun(Result (*f)(Arg));

Returns: pointer_to_unary_function<Arg, Result>(f).

template <class Arg1, class Arg2, class Result> class pointer_to_binary_function : public binary_function<Arg1,Arg2,Result> { public: explicit pointer_to_binary_function(Result (*f)(Arg1, Arg2)); Result operator()(Arg1 x, Arg2 y) const; };

operator() returns f(x,y).

template <class Arg1, class Arg2, class Result> pointer_to_binary_function<Arg1,Arg2,Result> ptr_fun(Result (*f)(Arg1, Arg2));

Returns: pointer_to_binary_function<Arg1,Arg2,Result>(f).

Example:

int compare(const char*, const char*);
replace_if(v.begin(), v.end(),
  not1(bind2nd(ptr_fun(compare), "abc")), "def");

replaces each abc with def in sequence v.  — end example ]

D.8.2.2 Adaptors for pointers to members [depr.member.pointer.adaptors]

The purpose of the following is to provide the same facilities for pointer to members as those provided for pointers to functions in [depr.function.pointer.adaptors].

template <class S, class T> class mem_fun_t : public unary_function<T*, S> { public: explicit mem_fun_t(S (T::*p)()); S operator()(T* p) const; };

mem_fun_t calls the member function it is initialized with given a pointer argument.

template <class S, class T, class A> class mem_fun1_t : public binary_function<T*, A, S> { public: explicit mem_fun1_t(S (T::*p)(A)); S operator()(T* p, A x) const; };

mem_fun1_t calls the member function it is initialized with given a pointer argument and an additional argument of the appropriate type.

template<class S, class T> mem_fun_t<S,T> mem_fun(S (T::*f)()); template<class S, class T, class A> mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A));

mem_fun(&X::f) returns an object through which X::f can be called given a pointer to an X followed by the argument required for f (if any).

template <class S, class T> class mem_fun_ref_t : public unary_function<T, S> { public: explicit mem_fun_ref_t(S (T::*p)()); S operator()(T& p) const; };

mem_fun_ref_t calls the member function it is initialized with given a reference argument.

template <class S, class T, class A> class mem_fun1_ref_t : public binary_function<T, A, S> { public: explicit mem_fun1_ref_t(S (T::*p)(A)); S operator()(T& p, A x) const; };

mem_fun1_ref_t calls the member function it is initialized with given a reference argument and an additional argument of the appropriate type.

template<class S, class T> mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)()); template<class S, class T, class A> mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A));

mem_fun_ref(&X::f) returns an object through which X::f can be called given a reference to an X followed by the argument required for f (if any).

template <class S, class T> class const_mem_fun_t : public unary_function<const T*, S> { public: explicit const_mem_fun_t(S (T::*p)() const); S operator()(const T* p) const; };

const_mem_fun_t calls the member function it is initialized with given a pointer argument.

template <class S, class T, class A> class const_mem_fun1_t : public binary_function<const T*, A, S> { public: explicit const_mem_fun1_t(S (T::*p)(A) const); S operator()(const T* p, A x) const; };

const_mem_fun1_t calls the member function it is initialized with given a pointer argument and an additional argument of the appropriate type.

template<class S, class T> const_mem_fun_t<S,T> mem_fun(S (T::*f)() const); template<class S, class T, class A> const_mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A) const);

mem_fun(&X::f) returns an object through which X::f can be called given a pointer to an X followed by the argument required for f (if any).

template <class S, class T> class const_mem_fun_ref_t : public unary_function<T, S> { public: explicit const_mem_fun_ref_t(S (T::*p)() const); S operator()(const T& p) const; };

const_mem_fun_ref_t calls the member function it is initialized with given a reference argument.

template <class S, class T, class A> class const_mem_fun1_ref_t : public binary_function<T, A, S> { public: explicit const_mem_fun1_ref_t(S (T::*p)(A) const); S operator()(const T& p, A x) const; };

const_mem_fun1_ref_t calls the member function it is initialized with given a reference argument and an additional argument of the appropriate type.

template<class S, class T> const_mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)() const); template<class S, class T, class A> const_mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A) const);

mem_fun_ref(&X::f) returns an object through which X::f can be called given a reference to an X followed by the argument required for f (if any).