vtf-logo

linear.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00008 #if !defined(__ads_functor_Linear_h__)
00009 #define __ads_functor_Linear_h__
00010 
00011 #include "../defs.h"
00012 
00013 #include <functional>
00014 
00015 BEGIN_NAMESPACE_ADS
00016 
00017 //-----------------------------------------------------------------------------
00021 // @{
00022 
00024 template<typename T>
00025 class UnaryLinear : 
00026   public std::unary_function<T,T> {
00027 private:
00028 
00029   //
00030   // Private types.
00031   //
00032 
00033   typedef std::unary_function<T,T> Base;
00034 
00035 public:
00036 
00037   //
00038   //Public types.
00039   //
00040 
00042   typedef typename Base::argument_type argument_type;
00044   typedef typename Base::result_type result_type;
00045 
00046   //
00047   // Member data.
00048   //
00049 
00051   T a;
00053   T b;
00054 
00055   //
00056   // Constructors.
00057   //
00058 
00060   UnaryLinear(const T a_ = 0, const T b_ = 0) :
00061     a(a_),
00062     b(b_)
00063   {}
00064 
00065   // The default copy and assignment and destructor are fine.
00066 
00067   //
00068   // Functor.
00069   //
00070 
00072   result_type
00073   operator()(const argument_type& x) const {
00074     return a * x + b;
00075   }
00076 
00077 };
00078 
00080 
00083 template<typename T>
00084 inline
00085 UnaryLinear<T>
00086 unary_linear(const T a, const T b) {
00087   return UnaryLinear<T>(a, b);
00088 }
00089 
00091 
00094 template<typename T>
00095 inline
00096 UnaryLinear<T>
00097 unary_linear() {
00098   return UnaryLinear<T>();
00099 }
00100 
00101 // @}
00102 
00103 END_NAMESPACE_ADS
00104 
00105 #endif

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