\(\newcommand{\B}[1]{ {\bf #1} }\) \(\newcommand{\R}[1]{ {\rm #1} }\)
cpp_fun_obj¶
View page sourceThe New Abstract Class for a C++ Function Object¶
Syntax¶
# include <cmpad/fun_obj.hppcmpad::fun_obj < Vector > funcmpad::fun_obj < Vector > :: scalar_typesetup ( option )domain ( )range ( )Source Code¶
# include <cmpad/option_t.hpp>
namespace cmpad {
template <class Vector> struct fun_obj {
//
// scalar_type
typedef typename Vector::value_type scalar_type;
//
// setup
virtual void setup(const option_t& option) = 0;
//
// option
virtual const option_t& option(void) const = 0;
//
// domain
virtual size_t domain(void) const = 0;
//
// range
//
virtual size_t range(void) const = 0;
//
// operator()
virtual const Vector& operator()(const Vector& x) = 0;
};
}
vector_type¶
A derived class must define vector_type to be the same as Vector . This is intended for use when derived class type is passed as a template parameter.
scalar_type¶
A derived class must also define scalar_type to be the type of the elements of vec ; i.e.,
typedef typename Vector::value_type scalar_type
If i is a positive integer constant and s, t are scalar_type objects, the following operations must be defined:
The constructors: scalar_type (i), scalar_type (s) .
This binary operations: s + t , s - t , s * t , s / t .
Vector¶
The fun_obj Vector class must support the following where vec is a Vector object:
Vector::value_type¶
is the type of the elements of vec .
vec.resize(n)¶
resize the vector to have size n where n is a size_t object.
vec.size()¶
returns a size_t that is the current size of the vector.
vec[i]¶
returns a reference, or constant reference, to the i-th element of vec
where i is an size_t .
fun¶
This is the function object. The corresponding function call, y = fun ( x ), computes y as a function of x .
setup¶
The function object is initialized using the setup syntax.
The setup can (and should) do calculations that do not depend on x
(to make the evaluation of the function call faster).
option¶
This interface does not place any restrictions on the content of option .
domain¶
The return value is the dimension of the domain space for this function; i.e. the size of x. It likely depends on the value of option.
range¶
The return value is the dimension of the range space for this function; i.e. the size of y. It likely depends on the value of option.
x¶
This Vector has size n and is the point at which the function is evaluated.
y¶
This Vector has size m and is the function value corresponding to x.
Example¶
xam_fun_obj.cpp is an example and test that uses this function.