// IBM_PROLOG_BEGIN_TAG // This is an automatically generated prolog. // // $Source: src/include/functional $ // // IBM CONFIDENTIAL // // COPYRIGHT International Business Machines Corp. 2011 // // p1 // // Object Code Only (OCO) source materials // Licensed Internal Code Source Materials // IBM HostBoot Licensed Internal Code // // The source code for this program is not published or other- // wise divested of its trade secrets, irrespective of what has // been deposited with the U.S. Copyright Office. // // Origin: 30 // // IBM_PROLOG_END #ifndef _FUNCTIONAL_H #define _FUNCTIONAL_H // See C++ spec namespace std { template struct binary_function { typedef A1 first_argument_type; ///< type of the first argument typedef A2 second_argument_type; ///< type of the second argument typedef R result_type; ///< type of the return type }; template struct unary_function { typedef A argument_type; typedef R result_type; }; /** * less template */ template struct less : public binary_function { /** * operator() * @param[in] x first object * @param[in] y second object * @return true if x < y otherwise false */ bool operator()(const T& x, const T& y) const { return x < y; } }; template struct greater : public binary_function { /** * operator() * @param[in] x first object * @param[in] y second object * @return true if x > y otherwise false */ bool operator()(const T& x, const T& y) const { return x > y; } }; // --------------- mem_fun templates --------------- // template struct mem_fun_t : public unary_function { explicit mem_fun_t(Result (X::*f)()) : func(f) {} Result operator()(X* x) const { return (x->*func)(); } private: Result (X::*func)(); }; template struct const_mem_fun_t : public unary_function { explicit const_mem_fun_t(Result (X::*f)() const) : func(f) {} Result operator()(const X* x) const { return (x->*func)(); } private: Result (X::*func)() const; }; template mem_fun_t mem_fun(Result (X::*f)()) { return mem_fun_t(f); } template const_mem_fun_t mem_fun(Result (X::*f)() const) { return const_mem_fun_t(f); } // --------------- mem_fun1 templates --------------- // template struct mem_fun1_t : public binary_function { explicit mem_fun1_t(Result (X::*f)(Arg)) : func(f) {} Result operator()(X* x, Arg a) const { return (x->*func)(a); } private: Result (X::*func)(Arg); }; template struct const_mem_fun1_t : public binary_function { explicit const_mem_fun1_t(Result (X::*f)(Arg) const) : func(f) {} Result operator()(const X* x, Arg a) const { return (x->*func)(a); } private: Result (X::*func)(Arg) const; }; template mem_fun1_t mem_fun(Result (X::*f)(Arg)) { return mem_fun1_t(f); } template const_mem_fun1_t mem_fun(Result (X::*f)(Arg) const) { return const_mem_fun1_t(f); } // --------------- mem_fun_ref templates --------------- // template struct mem_fun_ref_t : public unary_function { explicit mem_fun_ref_t(Result (X::*f)()) : func(f) {} Result operator()(X& x) const { return (x.*func)(); } private: Result (X::*func)(); }; template struct const_mem_fun_ref_t : public unary_function { explicit const_mem_fun_ref_t(Result (X::*f)() const) : func(f) {} Result operator()(const X& x) const { return (x.*func)(); } private: Result (X::*func)() const; }; template mem_fun_ref_t mem_fun_ref(Result (X::*f)()) { return mem_fun_ref_t(f); } template const_mem_fun_ref_t mem_fun_ref(Result (X::*f)() const) { return const_mem_fun_ref_t(f); } // --------------- mem_fun1_ref templates --------------- // template struct mem_fun1_ref_t : public binary_function { explicit mem_fun1_ref_t(Result (X::*f)(Arg)) : func(f) {} Result operator()(X& x, Arg a) const { return (x.*func)(a); } private: Result (X::*func)(Arg); }; template struct const_mem_fun1_ref_t : public binary_function { explicit const_mem_fun1_ref_t(Result (X::*f)(Arg) const) : func(f) {} Result operator()(const X& x, Arg a) const { return (x.*func)(a); } private: Result (X::*func)(Arg) const; }; template mem_fun1_ref_t mem_fun_ref(Result (X::*f)(Arg)) { return mem_fun1_ref_t(f); } template const_mem_fun1_ref_t mem_fun_ref(Result (X::*f)(Arg) const) { return const_mem_fun1_ref_t(f); } // --------------- bind1st templates --------------- // template struct binder1st : public unary_function< typename AdaptableBinaryFunction::second_argument_type, typename AdaptableBinaryFunction::result_type > { binder1st(const AdaptableBinaryFunction& F, typename AdaptableBinaryFunction::first_argument_type c) : func(F), arg(c) {} typename AdaptableBinaryFunction::result_type operator()(const typename AdaptableBinaryFunction::second_argument_type& x) const { return func(arg, x); } private: AdaptableBinaryFunction func; typename AdaptableBinaryFunction::first_argument_type arg; }; template binder1st bind1st(const AdaptableBinaryFunction& F, const T& c) { return binder1st(F, typename AdaptableBinaryFunction::first_argument_type(c)); }; // --------------- bind2nd templates --------------- // template struct binder2nd : public unary_function< typename AdaptableBinaryFunction::first_argument_type, typename AdaptableBinaryFunction::result_type > { binder2nd(const AdaptableBinaryFunction& F, typename AdaptableBinaryFunction::second_argument_type c) : func(F), arg(c) {} typename AdaptableBinaryFunction::result_type operator()(const typename AdaptableBinaryFunction::first_argument_type& x) const { return func(x, arg); } private: AdaptableBinaryFunction func; typename AdaptableBinaryFunction::second_argument_type arg; }; template binder2nd bind2nd(const AdaptableBinaryFunction& F, const T& c) { return binder2nd(F, typename AdaptableBinaryFunction::second_argument_type(c)); }; }; #endif /* vim: set filetype=cpp : */