Changeset 1003 for trunk/yat/utility
 Timestamp:
 Jan 18, 2008, 11:13:13 PM (15 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/yat/utility/stl_utility.h
r1000 r1003 36 36 37 37 #include <algorithm> 38 #include <functional> 38 39 #include <ostream> 39 40 #include <string> … … 56 57 namespace yat { 57 58 namespace utility { 59 60 /** 61 Functor class taking absolute value 62 */ 63 template<typename T> 64 struct abs : std::unary_function<T, T> 65 { 66 /** 67 \return absolute value 68 */ 69 inline T operator()(T x) const 70 { return std::abs(x); } 71 }; 72 73 /** 74 See The C++ Standard Library  A Tutorial and Reference by 75 Nicolai M. Josuttis 76 77 If f is a binary functor, both g and h are unary functors, and 78 return type of g (and h) is convertible to F's argument type, 79 then compose_f_gx_hy can be used to create a functor equivalent 80 to \f$ f(g(x), h(y)) \f$ 81 */ 82 template<class F, class G, class H> 83 class compose_f_gx_hy 84 { 85 public: 86 /** 87 \brief Constructor 88 */ 89 compose_f_gx_hy(F f, G g, H h) 90 : f_(f), g_(g), h_(h) {} 91 92 /** 93 \brief Does the work 94 */ 95 bool 96 operator()(double x, 97 double y) const 98 { 99 return f_(g_(x), h_(y)); 100 } 101 102 private: 103 F f_; 104 G g_; 105 H h_; 106 }; 107 108 /** 109 Convenient function to create a compose_f_gx_hy. 110 111 \see std::make_pair 112 */ 113 template<class F, class G, class H> 114 compose_f_gx_hy<F, G, H> make_compose_f_gx_hy(F f, G g, H h) 115 { 116 return compose_f_gx_hy<F,G,H>(f,g,h); 117 } 58 118 59 119 /**
Note: See TracChangeset
for help on using the changeset viewer.