Blitz logo

Blitz Devel :

From: Derrick Bass (derrick_at_[hidden])
Date: 2003-07-27 16:15:02


I recently ran across an interesting problem using Blitz and
non-standard numeric types.

The trouble is that Blitz assumes it will find functions like sqrt,
tan, etc in the std namespace, but for a user defined class or other
non-native type that is almost never true.

I've been trying to think of a good solution to this problem that would
require minimal user intervention. The best I can come up with is to
have using directives in the apply method of BZ_DEFINE_UNARY_FUNC. In
other words, replace it with something like this
     static inline T_numtype
     apply(T_numtype1 a)
     { BZ_USING(BZ_MATHFN_SCOPE(fun)); return fun(a); }
(BZ_USING would have to be defined) and replace the invocation of the
macro, which currently goes like this
BZ_DEFINE_UNARY_FUNC(Fn_sqrt,BZ_MATHFN_SCOPE(sqrt))
with
BZ_DEFINE_UNARY_FUNC(Fn_sqrt, sqrt)

This works for classes that have math functions defined in the global
namespace. My knowledge of C++ is a little unclear on this point: will
it work for classes that have their own namespace so long as the
namespace (or the desired function) has a using directive in effect at
the time of instantiation?

Is there a better way?

Derrick