lines 8-131 of file: cpp/include/cmpad/fun_obj.hpp {xrst_begin cpp_fun_obj} {xrst_spell vec resize th typedef typename } The New Abstract Class for a C++ Function Object ################################################ Syntax ****** | |tab| ``# include *fun* | |tab| ``cmpad::fun_obj`` < *Vector* > :: ``scalar_type`` | |tab| *fun* . ``setup`` ( *option* ) | |tab| *fun* . ``domain`` ( ) | |tab| *fun* . ``range`` ( ) | |tab| *y* = *fun* ( *x* ) Source Code *********** {xrst_literal // BEGIN C++ // END C++ } 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., {xrst_code cpp} typedef typename Vector::value_type scalar_type {xrst_code} 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*. {xrst_toc_hidden cpp/xam/fun_obj.cpp } Example ******* :ref:`xam_fun_obj.cpp-name` is an example and test that uses this function. {xrst_end cpp_fun_obj}