/* IBM_PROLOG_BEGIN_TAG */ /* This is an automatically generated prolog. */ /* */ /* $Source: src/include/functional $ */ /* */ /* OpenPOWER HostBoot Project */ /* */ /* Contributors Listed Below - COPYRIGHT 2011,2018 */ /* [+] International Business Machines Corp. */ /* */ /* */ /* Licensed under the Apache License, Version 2.0 (the "License"); */ /* you may not use this file except in compliance with the License. */ /* You may obtain a copy of the License at */ /* */ /* http://www.apache.org/licenses/LICENSE-2.0 */ /* */ /* Unless required by applicable law or agreed to in writing, software */ /* distributed under the License is distributed on an "AS IS" BASIS, */ /* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or */ /* implied. See the License for the specific language governing */ /* permissions and limitations under the License. */ /* */ /* IBM_PROLOG_END_TAG */ #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; } }; /** * less_equal template */ template struct less_equal : 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; } }; /** * greater template */ 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; } }; /** * greater_equal template */ template struct greater_equal : 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; } }; /** * not_equal_to template */ template struct not_equal_to : 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; } }; /** * equal_to template */ template struct equal_to : 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; } }; // --------------- ptr_fun templates --------------- // template struct pointer_to_unary_function : public unary_function { explicit pointer_to_unary_function(Result (*f)(A1)) : func(f) {} Result operator()(A1 a1) const { return (*func)(a1); } protected: Result (*func)(A1); }; template pointer_to_unary_function ptr_fun(Result (*f)(A1)) { return pointer_to_unary_function(f); } template struct pointer_to_binary_function : public binary_function { explicit pointer_to_binary_function(Result (*f)(A1, A2)) : func(f) {} Result operator()(A1 a1, A2 a2) const { return (*func)(a1,a2); } protected: Result (*func)(A1,A2); }; template pointer_to_binary_function ptr_fun(Result (*f)(A1,A2)) { return pointer_to_binary_function(f); } // --------------- 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)(); } protected: 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)(); } protected: 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); } protected: 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); } protected: 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)(); } protected: 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)(); } protected: 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); } protected: 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); } protected: 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); } protected: 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); } protected: 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 : */