Functors

Functors offers a number of Function Objects for various purposes. The functors are grouped in several categories.

Some mathematic functions will try to use the GSL if USE_GSL is defined. In that case, you will have to link against GSL libraries.

List of functors

Common

  template <typename TSrc, typename TDest>
StaticCaster  

  value_type  
Type of the parameters for operator(), alias for TSrc.
  result_type  
Return type of operator(), alias for TDest.
  StaticCaster<TSrc, TDest>()  
Constructor.
  TDest operator()(const TSrc &src) const  
Return static_cast<TDest>(src)

  template <T>
Printer  

  value_type  
Type of the parameters for operator().
  result_type  
Return type of operator(), i.e. void.
  Printer<T>(std::string _delimiter = " ")  
Constructor
  void operator()(const T &item) const  
Prints "item" and a delimiter to the stdout.

  template <T, U>
Select1st  

  value_type  
Type of the parameters for operator(), alias for std::pair<T, U>.
  result_type  
Return type of operator(), alias for template parameter T.
  Select1st<T, U>()  
Constructor
  T operator()(const std::pair<T, U> &p) const  
Returns "p.first".

  template <T1, T2>
Select2nd  

  value_type  
Type of the parameters for operator(), alias for std::pair<T, U>.
  result_type  
Return type of operator(), alias for template parameter U.
  Select2nd<T, U>()  
Constructor
  U operator()(const std::pair<T, U> &p) const  
Returns "p.second".

  template <R>
Chooser1  

  value_type  
Type of the parameters for operator(), alias for template parameter R.
  result_type  
Return type of operator(), alias for template parameter R.
  Chooser1<R>(R trueValue, R falseValue)  
Constructor
  R operator()(const bool &b) const  
Returns "b ? trueValue : falseValue", chooses one of the specified values depending on the input.

  template <T, R, Operator>
Chooser1Op  

  value_type  
Type of the parameters for operator(), alias for template parameter T.
  result_type  
Return type of operator(), alias for template parameter R.
  Chooser1Op<R>(Operator op, R trueValue, R falseValue)  
Constructor
  R operator()(const T &o)  
Returns "op(o) ? trueValue : falseValue", applies the specified Operator to the input and chooses one of the specified values.

  template <T, R, Operator>
Chooser2Op  

  value_type  
Type of the parameters for operator(), alias for template parameter T.
  result_type  
Return type of operator(), alias for template parameter R.
  Chooser2<R>(Operator op, R trueValue, R falseValue)  
Constructor
  R operator()(const T &lhs, const T &rhs)
Returns "op(lhs, rhs) ? trueValue : falseValue", applies the specified binary Operator to the input and chooses one of the specified values.

Binary Functions

  template <T>
binary_and  

  value_type  
Type of the parameters for operator(), alias for template parameter T.
  result_type  
Return type of operator(), alias for template parameter T.
  binary_and<T>()  
Constructor
  T operator()(const T &lhs, const T &rhs) const  
Returns "lhs & rhs", the binary operator AND applied to "lhs" and "rhs".

  template <T>
binary_or  

  value_type  
Type of the parameters for operator(), alias for template parameter T.
  result_type  
Return type of operator(), alias for template parameter T.
  binary_or<T>()  
Constructor
  T operator()(const T &lhs, const T &rhs) const  
Returns "lhs | rhs", the binary operator OR applied to "lhs" and "rhs".

  template <T>
binary_xor  

  value_type  
Type of the parameters for operator(), alias for template parameter T.
  result_type  
Return type of operator(), alias for template parameter T.
  binary_xor<T>()  
Constructor
  T operator()(const T &lhs, const T &rhs) const  
Returns lhs ^ rhs, the binary operator XOR applied to "lhs" and "rhs".

  template <T>
binary_not  

  value_type  
Type of the parameters for operator(), alias for template parameter T.
  result_type  
Return type of operator(), alias for template parameter T.
  binary_not<T>()  
Constructor
  T operator()(const T &o) const  
Returns ~o, the binary operator NOT applied to o.

Math

  template <class Vector, typename register_type = Vector::value_type>
Rotator3D  

A Rotator3D applies a 3D rotation along the specified axis to a 3D Vector. The Vector class can essientially be any container whose size equals 3. The template parameter register_type corresponds to the type used for calculations, for example, one may choose to have a Vector of ints, but let the calculations be performed as floats.

  value_type  
Alias for value_type for template parameter Vector.
  result_type  
Return type of operator(), alias for template parameter Vector.
  Rotator3D<Vector>(unsigned axis, register_type angle)  
Constructor. Vectors will be rotated angle radians around the given axis.
  Vector operator()(const Vector &v) const  
Rotates v and returns the result.

  template <class Function>
Derivative  

The template parameters class Function must offer a typedef for value_type and an operator of the following form:
  value_type operator()(const value_type &x) const  
The class Function is thus assumed to model a mathematic function with fixed behaviour, which is enforced by the constness of the operator.

The Derivative computes a numerical approximation of the derivative of a given function, taking care of numerical precision and stability.

  value_type  
An alias for typename "Function::value_type".
  result_type  
Return type of operator().
  Derivative<Function>(const Function &f)  
Constructor. Parameter f must be a functor implementing a Function as specified.
  value_type operator()(const value_type &x) const  
Returns the derivative of Function f in point x.

  template <typename T>
class LinearFunc  

Models the function y = ax + b.

  value_type  
Type of the parameters for operator(), alias for template parameter T.
  result_type  
Return type of operator(), alias for template parameter T.
  LinearFunc<T>(const T a, const T b)  
Constructor.
  T operator()(const T &x) const  
Returns ax + b.


  template <typename T>
class QuadraticFunc  

Models the function y = ax^2 + bx + c.

  value_type  
Type of the parameters for operator(), alias for template parameter T.
  result_type  
Return type of operator(), alias for template parameter T.
  QuadraticFunc<T>(const T a, const T b, const T c)  
Constructor.
  T operator()(const T &x) const  
Returns ax^2 + bx + c.


  template <typename T, unsigned n>
class Polynomial  

Models an nth degree polynomial function. Keep in mind that an nth degree polynomial has n + 1 coefficients.

  value_type  
Type of the parameters for operator(), alias for template parameter T.
  result_type  
Return type of operator(), alias for template parameter T.
  template <typename Iterator>
Polynomial<T, n>(Iterator begin, Iterator end)  
Constructor. The elements in the range begin to end are the coefficients of the polynomial function y, where the ith element in the range corresponds to the coefficient of x^i. Keep in mind that there must be n + 1 elements in the given range!
  T operator()(T x) const  
Returns the value of y at point x.


  template <typename T>
class Gaussian  

  value_type  
Type of the parameters for operator(), alias for template parameter T.
  result_type  
Return type of operator(), alias for template parameter T.
  Gaussian(const T mu, const T sigmaSq)  
Constructor, muis the mean af the distribution and the variance is given by sigmaSq.
  T operator()(const T &x) const  
Returns value of the standard Gaussian probability density function at location x.

  template <typename T>
class Clamp  

Clamp a value between two specified values.
  value_type  
Type of the parameters for operator(), alias for template parameter T.
  result_type  
Return type of operator(), alias for template parameter T.
  Clamp<T>(const T low, const T high)  
Constructor
  T operator()(const T &x) const  
Returns the value in the range [low, high] that is closest to x.

  template <typename T>
struct Square  

  value_type  
Type of the parameters for operator(), alias for template parameter T.
  result_type  
Return type of operator(), alias for template parameter T.
  T operator()(const T &x) const  
Return the square of x.

  
template <typename T, typename U, class Operator = std::less<T> >
class PairFirstCompare  

  value_type  
Type of the objects to be compared, alias for template parameter T.
  result_type  
Return type of operator().
  T operator()(const T &lhs, const std::pair<T, U> &rhs) const  
Compares lhs to rhs.first.
  T operator()(const std::pair<T, U> &lhs, const T &rhs) const  
Compares lhs.first to rhs.
  T operator()(const std::pair<T, U> &lhs,
	     const std::pair<T, U> &rhs) const  
Compares lhs.first to rhs.first.