Blitz logo

Blitz Support :

From: Derrick Bass (derrick_at_[hidden])
Date: 2003-06-12 14:03:32


> Hi, I'd like to use a BZ_DECLARE_FUNCTION on a function object. i.e.
> something like.

There is support for this in the CVS tree. I guess there is not yet any
documentation. But take a look at the comments at the beginning of the
file functorExpr.h (I am attaching an excerpt below). If the
instructions are not clear, or you have further questions, please feel
free to contact me.

Derrick Bass

    If you have a functor, add the following to your (public) class
declaration:

    BZ_DECLARE_FUNCTOR(classname) // for one argument functors
    BZ_DECLARE_FUNCTOR2(classname) // for two argument functors
    BZ_DECLARE_FUNCTOR3(classname) // for three argument functors

    or

    BZ_DECLARE_FUNCTOR_RET(classname, returnType)
    BZ_DECLARE_FUNCTOR2_RET(classname, returnType)
    BZ_DECLARE_FUNCTOR3_RET(classname, returnType)

    for classes whose operator() has a return type that is not what you
would
    deduce from the usual C++ promotion rules (e.g., takes two doubles
and
    returns a bool).

    You can then use your class in Blitz++ expressions and no
temporaries will
    be generated. For example, assuming that your class is named T, and
that
    A, B and C are Arrays, you can write

    T classInstance( ... );
    A = C + classInstance(B * tensor::i);
    A = C + classInstance(tensor::i, tensor::j)

    All the member functions to be applied must be declared const.

    There is also some support for classes where the source code is not
    available or not to be tampered with. For example,

    A = C + applyFunctor(classInstance, B * tensor::i);
    A = C + applyFunctor(classInstance, tensor::i, tensor::j);