Changeset 2274
 Timestamp:
 Jun 23, 2010, 12:02:30 AM (13 years ago)
 Location:
 trunk
 Files:

 2 edited
Legend:
 Unmodified
 Added
 Removed

trunk/test/utility_test.cc
r2273 r2274 63 63 void test_less_nan(test::Suite& suite); 64 64 void test_ptr_compare(test::Suite& suite); 65 void test_compose_functors(test::Suite& suite); 65 66 66 67 int main(int argc, char* argv[]) … … 175 176 test_load2(suite); 176 177 178 test_compose_functors(suite); 179 177 180 return suite.return_value(); 178 181 } … … 200 203 suite.add(false); 201 204 } 205 206 207 void test_compose_functors(test::Suite& suite) 208 { 209 typedef utility::abs<double> U1; 210 // we use float here to check conversion from float to double in functors 211 typedef utility::Exp<float> U2; 212 typedef std::plus<double> B; 213 U1 u1; 214 U2 u2; 215 B b; 216 217 utility::compose_f_gx_hy<B, U1, U2> binary = 218 utility::make_compose_f_gx_hy(b, u1, u2); 219 220 utility::compose_f_gxy<U2, B> binary2 = 221 utility::make_compose_f_gxy(u2, b); 222 223 utility::compose_f_gx<U1, U2> unary = 224 utility::make_compose_f_gx(u1, u2); 225 } 226 202 227 203 228 
trunk/yat/utility/stl_utility.h
r2239 r2274 106 106 */ 107 107 template<class F, class G, class H> 108 class compose_f_gx_hy : std::binary_function<typename G::argument_type, 109 typename H::argument_type, 110 typename F::result_type> 108 class compose_f_gx_hy : 109 public std::binary_function<typename G::argument_type, 110 typename H::argument_type, 111 typename F::result_type> 111 112 { 112 113 public: … … 115 116 */ 116 117 compose_f_gx_hy(F f, G g, H h) 117 : f_(f), g_(g), h_(h) {} 118 : f_(f), g_(g), h_(h) 119 { 120 BOOST_CONCEPT_ASSERT((boost::Convertible<typename G::result_type 121 , typename F::first_argument_type>)); 122 BOOST_CONCEPT_ASSERT((boost::Convertible<typename H::result_type 123 , typename F::second_argument_type>)); 124 125 } 118 126 119 127 /** … … 136 144 Convenient function to create a compose_f_gx_hy. 137 145 146 \relates compose_f_gx_hy 147 138 148 \see std::make_pair 139 149 */ … … 143 153 return compose_f_gx_hy<F,G,H>(f,g,h); 144 154 } 155 156 157 /** 158 See The C++ Standard Library  A Tutorial and Reference by 159 Nicolai M. Josuttis 160 161 If f is a unary functor, g is a binary functor, and return type 162 of g is convertible to F's argument type, then 163 compose_f_gxy can be used to create a functor equivalent to 164 \f$ f(g(x,y)) \f$ 165 166 F must be an adaptable unary functor 167 G must be an adaptable binary functor 168 169 \since New in yat 0.7 170 */ 171 template<class F, class G> 172 class compose_f_gxy : 173 public std::binary_function<typename G::first_argument_type, 174 typename G::second_argument_type, 175 typename F::result_type> 176 { 177 public: 178 /** 179 \brief Constructor 180 */ 181 compose_f_gxy(F f, G g) 182 : f_(f), g_(g) 183 { 184 BOOST_CONCEPT_ASSERT((boost::Convertible<typename G::result_type 185 , typename F::argument_type>)); 186 } 187 188 /** 189 \brief Does the work 190 */ 191 typename F::result_type 192 operator()(typename G::first_argument_type x, 193 typename G::second_argument_type y) const 194 { 195 return f_(g_(x,y)); 196 } 197 198 private: 199 F f_; 200 G g_; 201 }; 202 203 /** 204 Convenient function to create a compose_f_gxy. 205 206 \relates compose_f_gxy 207 208 \see std::make_pair 209 210 \since New in yat 0.7 211 */ 212 template<class F, class G> 213 compose_f_gxy<F, G> make_compose_f_gxy(F f, G g) 214 { 215 return compose_f_gxy<F,G>(f,g); 216 } 217 218 219 /** 220 See The C++ Standard Library  A Tutorial and Reference by 221 Nicolai M. Josuttis 222 223 If f is a unary functor, g is a unary functor, and return type of 224 g is convertible to F's argument type, then compose_f_gx can be 225 used to create a functor equivalent to \f$ f(g(x)) \f$ 226 227 F must be an adaptable binary functor 228 G must be an adaptable unary functor 229 230 \since New in yat 0.7 231 */ 232 template<class F, class G> 233 class compose_f_gx : public std::unary_function<typename G::argument_type, 234 typename F::result_type> 235 { 236 public: 237 /** 238 \brief Constructor 239 */ 240 compose_f_gx(F f, G g) 241 : f_(f), g_(g) 242 { 243 BOOST_CONCEPT_ASSERT((boost::Convertible<typename G::result_type 244 , typename F::argument_type>)); 245 } 246 247 /** 248 \brief Does the work 249 */ 250 typename F::result_type 251 operator()(typename G::argument_type x) const 252 { 253 return f_(g_(x)); 254 } 255 256 private: 257 F f_; 258 G g_; 259 }; 260 261 /** 262 Convenient function to create a compose_f_gx. 263 264 \relates compose_f_gx 265 266 \see std::make_pair 267 268 \since New in yat 0.7 269 */ 270 template<class F, class G> 271 compose_f_gx<F, G> make_compose_f_gx(F f, G g) 272 { 273 return compose_f_gx<F,G>(f,g); 274 } 275 145 276 146 277 /**
Note: See TracChangeset
for help on using the changeset viewer.