Changeset 3082


Ignore:
Timestamp:
Sep 19, 2013, 1:54:15 AM (8 years ago)
Author:
Peter
Message:

new compose functor: compose_f_gx_hx

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/utility.cc

    r2963 r3082  
    262262  utility::compose_f_gx<U1, U2> unary;
    263263  unary = utility::make_compose_f_gx(u1, u2);
     264
     265  utility::compose_f_gx_hx<B, U1, U2> unary2;
     266  unary2 = utility::make_compose_f_gx_hx(b, u1, u2);
     267  if (!suite.add(suite.equal_fix(unary2(-2.0), 2.0 + std::exp(-2.0),1e-8)))
     268    suite.err() << "compose_f_gx_hx failed\n";
    264269}
    265270
  • trunk/yat/utility/stl_utility.h

    r2964 r3082  
    159159     - \c H::result_type is convertible to \c F::second_argument_type
    160160
    161      \see compose_f_gxy and compose_f_gx
     161     \see compose_f_gxy, compose_f_gx, and compose_f_gx_hx
    162162   */
    163163  template<class F, class G, class H>
     
    235235     - \c G::result_type is convertible to \c F::argument_type
    236236
    237      \see compose_f_gx_hy and compose_f_gx
     237     \see compose_f_gx_hy, compose_f_gx, and compose_f_gx_hx
    238238
    239239     \since New in yat 0.7
     
    310310     - \c G::result_type is convertible to \c F::argument_type
    311311
    312      \see compose_f_gx_hy and compose_f_gxy
     312     \see compose_f_gx_hy, compose_f_gxy, and compose_f_gx_hx
     313
     314     \see <a href="http://www.sgi.com/tech/stl/unary_compose.html">
     315     unary_compose</a> (SGI extension)
    313316
    314317     \since New in yat 0.7
     
    322325       \brief default constructor
    323326
    324        Requires that F and H have default constructors
     327       Requires that F and G have default constructors
    325328    */
    326329    compose_f_gx(void) {}
     
    363366  {
    364367    return compose_f_gx<F,G>(f,g);
     368  }
     369
     370
     371  /**
     372     If f is a binary functor, g and h a unary functors, and return
     373     types of g and h are convertible to F's argument type, then
     374     compose_f_gx_hx can be used to create a functor equivalent to \f$
     375     f(g(x), h(x)) \f$
     376
     377     - F must be an <a
     378     href="http://www.sgi.com/tech/stl/AdaptableBinaryFunction.html">
     379     AdaptableBinaryFunction</a>
     380     - G must be an <a
     381     href="http://www.sgi.com/tech/stl/AdaptableUnaryFunction.html">
     382     AdaptableUnaryFunction</a>
     383     - H must be an <a
     384     href="http://www.sgi.com/tech/stl/AdaptableUnaryFunction.html">
     385     AdaptableUnaryFunction</a>
     386     - \c G::result_type is convertible to \c F::first_argument_type
     387     - \c H::result_type is convertible to \c F::second_argument_type
     388
     389     \see compose_f_gx_hy, compose_f_gxy, and compose_f_gx
     390
     391     \see <a href="http://www.sgi.com/tech/stl/binary_compose.html">
     392     binary_compose</a> (SGI extension)
     393
     394     \since New in yat 0.11
     395   */
     396  template<class F, class G, class H>
     397  class compose_f_gx_hx : public std::unary_function<typename G::argument_type,
     398                                                     typename F::result_type>
     399  {
     400  public:
     401    /**
     402       \brief default constructor
     403
     404       Requires that F, G, and H have default constructors
     405    */
     406    compose_f_gx_hx(void) {}
     407
     408    /**
     409       \brief Constructor
     410     */
     411    compose_f_gx_hx(F f, G g, H h)
     412      : f_(f), g_(g), h_(h)
     413    {
     414      BOOST_CONCEPT_ASSERT((boost::Convertible<typename G::result_type
     415                            , typename F::first_argument_type>));
     416      BOOST_CONCEPT_ASSERT((boost::Convertible<typename H::result_type
     417                            , typename F::second_argument_type>));
     418    }
     419
     420    /**
     421       \brief Does the work
     422     */
     423    typename F::result_type
     424    operator()(typename G::argument_type x) const
     425    {
     426      return f_(g_(x), h_(x));
     427    }
     428
     429  private:
     430    F f_;
     431    G g_;
     432    H h_;
     433  };
     434
     435  /**
     436     Convenient function to create a compose_f_gx_hx.
     437
     438     \relates compose_f_gx_hx
     439
     440     \see std::make_pair
     441
     442     \since New in yat 0.11
     443  */
     444  template<class F, class G, class H>
     445  compose_f_gx_hx<F, G, H> make_compose_f_gx_hx(F f, G g, H h)
     446  {
     447    return compose_f_gx_hx<F,G,H>(f,g,h);
    365448  }
    366449
Note: See TracChangeset for help on using the changeset viewer.