vtf-logo

compose.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00019 #if !defined(__ads_compose_h__)
00020 #define __ads_compose_h__
00021 
00022 #include "../defs.h"
00023 
00024 #include <functional>
00025 
00026 BEGIN_NAMESPACE_ADS
00027 
00028 //-----------------------------------------------------------------------------
00042 // @{
00043 
00045 
00049 template <class F, class G>
00050 class unary_compose_unary_unary
00051   : public std::unary_function< typename G::argument_type,
00052                                 typename F::result_type >
00053 {
00054 private:
00055   typedef std::unary_function< typename G::argument_type,
00056                                typename F::result_type > base_type;
00057 protected:
00059   F _f;
00061   G _g;
00062 
00063 public:
00065   typedef typename base_type::argument_type argument_type;
00067   typedef typename base_type::result_type result_type;
00068 
00070   unary_compose_unary_unary() 
00071     : _f(), _g() 
00072   {}
00073 
00075   unary_compose_unary_unary( const F& f, const G& g ) 
00076     : _f( f ), _g( g ) 
00077   {}
00078 
00080   result_type
00081   operator()( const argument_type& x ) const {
00082     return _f( _g( x ) );
00083   }
00084 };
00085 
00086 
00088 template <class F, class G>
00089 class binary_compose_unary_binary
00090   : public std::binary_function< typename G::first_argument_type,
00091                                  typename G::second_argument_type,
00092                                  typename F::result_type >
00093 {
00094 private:
00095   typedef std::binary_function< typename G::first_argument_type,
00096                                 typename G::second_argument_type,
00097                                 typename F::result_type > base_type;
00098 protected:
00100   F _f;
00102   G _g;
00103 
00104 public:
00106   typedef typename base_type::first_argument_type first_argument_type;
00108   typedef typename base_type::second_argument_type second_argument_type;
00110   typedef typename base_type::result_type result_type;
00111 
00113   binary_compose_unary_binary()
00114     : _f(), _g() 
00115   {}
00116 
00118   binary_compose_unary_binary( const F& f, const G& g ) 
00119     : _f( f ), _g( g ) 
00120   {}
00121 
00123   result_type
00124   operator()( const first_argument_type& x, const second_argument_type& y ) 
00125     const {
00126     return _f( _g( x, y ) );
00127   }
00128 };
00129 
00130 
00132 
00136 template <class F, class G, class H>
00137 class unary_compose_binary_unary
00138   : public std::unary_function< typename G::argument_type,
00139                                 typename F::result_type >
00140 {
00141 private:
00142   typedef std::unary_function< typename G::argument_type,
00143                                typename F::result_type > base_type;
00144 protected:
00146   F _f;
00148   G _g;
00150   H _h;
00151 
00152 public:
00154   typedef typename base_type::argument_type argument_type;
00156   typedef typename base_type::result_type result_type;
00157 
00159   unary_compose_binary_unary()
00160     : _f(), _g(), _h() 
00161   {}
00162 
00164   unary_compose_binary_unary( const F& f, const G& g, const H& h ) 
00165     : _f( f ), _g( g ), _h( h ) 
00166   {}
00167 
00169   result_type
00170   operator()( const argument_type& x ) const {
00171     return _f( _g( x ), _h( x ) );
00172   }
00173 };
00174 
00175 
00177 template <class F, class G, class H>
00178 class binary_compose_binary_unary
00179   : public std::binary_function< typename G::argument_type,
00180                                  typename H::argument_type,
00181                                  typename F::result_type >
00182 {
00183 private:
00184   typedef std::binary_function< typename G::argument_type,
00185                                 typename H::argument_type,
00186                                 typename F::result_type > base_type;
00187 protected:
00189   F _f;
00191   G _g;
00193   H _h;
00194 
00195 public:
00197   typedef typename base_type::first_argument_type first_argument_type;
00199   typedef typename base_type::second_argument_type second_argument_type;
00201   typedef typename base_type::result_type result_type;
00202 
00204   binary_compose_binary_unary()
00205     : _f(), _g(), _h()
00206   {}
00207 
00209   binary_compose_binary_unary( const F& f, const G& g, const H& h ) 
00210     : _f( f ), _g( g ), _h( h )
00211   {}
00212 
00214   result_type
00215   operator()( const first_argument_type& x, const second_argument_type& y ) 
00216     const {
00217     return _f( _g( x ), _h( y ) );
00218   }
00219 
00220   // CONTINUE: Are these a good idea?  Should I add them to the rest of the 
00221   // functors?
00223   F&
00224   outer()
00225   {
00226     return _f;
00227   }
00228 
00230   G&
00231   first_inner()
00232   {
00233     return _g;
00234   }
00235 
00237   H&
00238   second_inner()
00239   {
00240     return _h;
00241   }
00242 };
00243 
00244 // @}
00245 
00246 END_NAMESPACE_ADS
00247 
00248 #endif

Generated on Fri Aug 24 12:55:23 2007 for Algorithms and Data Structures Package by  doxygen 1.4.7