00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef OLENA_CORE_COMPOSE_HH
00029 # define OLENA_CORE_COMPOSE_HH
00030
00031 # include <functional>
00032
00033 namespace oln {
00034
00035 namespace internal {
00036
00043 template< class F1, class F2 >
00044 struct compose_uu_ :
00045 public std::unary_function <typename F2::argument_type,
00046 typename F1::result_type>
00047 {
00048 typedef compose_uu_ self_type;
00049
00050 typename self_type::result_type
00051 operator()(typename self_type::argument_type arg) const
00052 {
00053 return f1_(f2_(arg));
00054 }
00055
00056 compose_uu_(const F1& f1, const F2& f2) : f1_(f1), f2_(f2) {}
00057
00058 private:
00059
00060 const F1 f1_;
00061 const F2 f2_;
00062
00063 };
00064
00072 template< class F1, class F2 >
00073 struct compose_ub_ :
00074 public std::binary_function <typename F2::first_argument_type,
00075 typename F2::second_argument_type,
00076 typename F1::result_type>
00077 {
00078 typedef compose_ub_ self_type;
00079
00080 typename self_type::result_type
00081 operator()(typename self_type::first_argument_type arg1,
00082 typename self_type::second_argument_type arg2) const
00083 {
00084 return f1_(f2_(arg1, arg2));
00085 }
00086
00087 compose_ub_(const F1& f1, const F2& f2) : f1_(f1), f2_(f2) {}
00088
00089 private:
00090
00091 const F1 f1_;
00092 const F2 f2_;
00093
00094 };
00095
00102 template< class F1, class F2 >
00103 struct compose_bu_ :
00104 public std::binary_function <typename F2::argument_type,
00105 typename F2::argument_type,
00106 typename F1::result_type>
00107 {
00108 typedef compose_bu_ self_type;
00109
00110 typename self_type::result_type
00111 operator()(typename self_type::first_argument_type arg1,
00112 typename self_type::second_argument_type arg2) const
00113 {
00114 return f1_(f2_(arg1), f2_(arg2));
00115 }
00116
00117 compose_bu_(const F1& f1, const F2& f2) : f1_(f1), f2_(f2) {}
00118
00119 private:
00120
00121 const F1 f1_;
00122 const F2 f2_;
00123
00124 };
00125
00126 }
00127
00128
00130 template<class UF1, class UF2>
00131 internal::compose_uu_<UF1, UF2>
00132 compose_uu(const UF1& f1, const UF2& f2)
00133 {
00134 return internal::compose_uu_<UF1, UF2>(f1, f2);
00135 }
00136
00138 template<class UF1, class BF2>
00139 internal::compose_ub_<UF1, BF2>
00140 compose_ub(const UF1& f1, const BF2& f2)
00141 {
00142 return internal::compose_ub_<UF1, BF2>(f1, f2);
00143 }
00144
00146 template<class BF1, class UF2>
00147 internal::compose_bu_<BF1, UF2>
00148 compose_bu(const BF1& f1, const UF2& f2)
00149 {
00150 return internal::compose_bu_<BF1, UF2>(f1, f2);
00151 }
00152
00158 template<class T>
00159 struct f_identity : std::unary_function<T, T>
00160 {
00161 T
00162 operator()(T t) const
00163 {
00164 return t;
00165 }
00166 };
00167
00168 }
00169
00170 #endif // OLENA_CORE_COMPOSE_HH