summaryrefslogtreecommitdiffstats
path: root/src/include/functional
diff options
context:
space:
mode:
authorPatrick Williams <iawillia@us.ibm.com>2012-05-14 12:29:39 -0500
committerA. Patrick Williams III <iawillia@us.ibm.com>2012-05-21 09:47:27 -0500
commit2a98222faf80705d4de4ed5703166802cdacc491 (patch)
treea43eea98e02cb1ff6138ead516dad88dba67c516 /src/include/functional
parent7fd3b786f79d8e9a5b0ab25593d81cb45c8cc1d7 (diff)
downloadblackbird-hostboot-2a98222faf80705d4de4ed5703166802cdacc491.tar.gz
blackbird-hostboot-2a98222faf80705d4de4ed5703166802cdacc491.zip
Enhanced STL capabilities.
- max_element - for_each - remove / remove_if - unique - sort - mem_fun / mem_fun_ref - bind1st / bind2nd RTC: 41636 Change-Id: Icf15ef90562ed20097306a15f4a314e05511b199 Reviewed-on: http://gfw160.austin.ibm.com:8080/gerrit/1068 Tested-by: Jenkins Server Reviewed-by: Douglas R. Gilbert <dgilbert@us.ibm.com> Reviewed-by: Bradley W. Bishop <bradleyb@us.ibm.com> Reviewed-by: Terry J. Opie <opiet@us.ibm.com> Reviewed-by: A. Patrick Williams III <iawillia@us.ibm.com>
Diffstat (limited to 'src/include/functional')
-rw-r--r--src/include/functional204
1 files changed, 204 insertions, 0 deletions
diff --git a/src/include/functional b/src/include/functional
index ac0b070f4..809116cf5 100644
--- a/src/include/functional
+++ b/src/include/functional
@@ -73,6 +73,210 @@ namespace std
{ return x > y; }
};
+// --------------- mem_fun templates --------------- //
+
+ template<typename Result, typename X>
+ struct mem_fun_t : public unary_function<X*, Result>
+ {
+ explicit mem_fun_t(Result (X::*f)()) : func(f) {}
+ Result operator()(X* x) const { return (x->*func)(); }
+
+ private:
+ Result (X::*func)();
+ };
+
+ template<typename Result, typename X>
+ struct const_mem_fun_t : public unary_function<X*, Result>
+ {
+ 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<typename Result, typename X>
+ mem_fun_t<Result, X> mem_fun(Result (X::*f)())
+ {
+ return mem_fun_t<Result, X>(f);
+ }
+
+ template<typename Result, typename X>
+ const_mem_fun_t<Result, X> mem_fun(Result (X::*f)() const)
+ {
+ return const_mem_fun_t<Result, X>(f);
+ }
+
+// --------------- mem_fun1 templates --------------- //
+
+ template<typename Result, typename X, typename Arg>
+ struct mem_fun1_t : public binary_function<X*, Arg, Result>
+ {
+ 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<typename Result, typename X, typename Arg>
+ struct const_mem_fun1_t : public binary_function<X*, Arg, Result>
+ {
+ 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<typename Result, typename X, typename Arg>
+ mem_fun1_t<Result, X, Arg> mem_fun(Result (X::*f)(Arg))
+ {
+ return mem_fun1_t<Result, X, Arg>(f);
+ }
+
+ template<typename Result, typename X, typename Arg>
+ const_mem_fun1_t<Result, X, Arg> mem_fun(Result (X::*f)(Arg) const)
+ {
+ return const_mem_fun1_t<Result, X, Arg>(f);
+ }
+
+// --------------- mem_fun_ref templates --------------- //
+
+ template<typename Result, typename X>
+ struct mem_fun_ref_t : public unary_function<X, Result>
+ {
+ explicit mem_fun_ref_t(Result (X::*f)()) : func(f) {}
+ Result operator()(X& x) const { return (x.*func)(); }
+
+ private:
+ Result (X::*func)();
+ };
+
+ template<typename Result, typename X>
+ struct const_mem_fun_ref_t : public unary_function<X, Result>
+ {
+ 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<typename Result, typename X>
+ mem_fun_ref_t<Result, X> mem_fun_ref(Result (X::*f)())
+ {
+ return mem_fun_ref_t<Result, X>(f);
+ }
+
+ template<typename Result, typename X>
+ const_mem_fun_ref_t<Result, X> mem_fun_ref(Result (X::*f)() const)
+ {
+ return const_mem_fun_ref_t<Result, X>(f);
+ }
+
+// --------------- mem_fun1_ref templates --------------- //
+
+ template<typename Result, typename X, typename Arg>
+ struct mem_fun1_ref_t : public binary_function<X, Arg, Result>
+ {
+ 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<typename Result, typename X, typename Arg>
+ struct const_mem_fun1_ref_t : public binary_function<X, Arg, Result>
+ {
+ 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<typename Result, typename X, typename Arg>
+ mem_fun1_ref_t<Result, X, Arg> mem_fun_ref(Result (X::*f)(Arg))
+ {
+ return mem_fun1_ref_t<Result, X, Arg>(f);
+ }
+
+ template<typename Result, typename X, typename Arg>
+ const_mem_fun1_ref_t<Result, X, Arg> mem_fun_ref(Result (X::*f)(Arg) const)
+ {
+ return const_mem_fun1_ref_t<Result, X, Arg>(f);
+ }
+
+// --------------- bind1st templates --------------- //
+
+ template<typename AdaptableBinaryFunction>
+ 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<typename AdaptableBinaryFunction, typename T>
+ binder1st<AdaptableBinaryFunction>
+ bind1st(const AdaptableBinaryFunction& F,
+ const T& c)
+ {
+ return binder1st<AdaptableBinaryFunction>(F,
+ typename AdaptableBinaryFunction::first_argument_type(c));
+ };
+
+// --------------- bind2nd templates --------------- //
+
+ template<typename AdaptableBinaryFunction>
+ 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<typename AdaptableBinaryFunction, typename T>
+ binder2nd<AdaptableBinaryFunction>
+ bind2nd(const AdaptableBinaryFunction& F,
+ const T& c)
+ {
+ return binder2nd<AdaptableBinaryFunction>(F,
+ typename AdaptableBinaryFunction::second_argument_type(c));
+ };
+
};
#endif
OpenPOWER on IntegriCloud