Blitz logo

Blitz Devel :

From: Julian C. Cummings (cummings_at_[hidden])
Date: 2003-07-28 12:38:44


Hi Derrick,

If all you really want to do is use math functions in the global namespace,
why not just modify the definition of BZ_MATHFN_SCOPE directly? This macro
is defined based on the configure process, but you can change it manually.
You would have to have a "using namespace std" directive to get the standard
math functions into the global namespace with most ANSI C++ compilers.

The more general problem you describe of users adding their own math
functions for their own types has a couple of solutions I can see. If the
functions are truly analogous to existing standard math functions and are
just being defined for new number types, the user could put their function
definitions into namespace std. C++ namespaces are open, so I can add new
stuff to namespace std if I want to. The more typical case is that both the
user-defined types and the new math functions will be defined in some other
namespace. In that case, you can use the existing BZ_DEFINE_UNARY_FUNC
macro to define an apply() method for the new types and functions and invoke
the math function from the proper namespace.

Regards, Julian C.

Dr. Julian C. Cummings
Staff Scientist, CACR/Caltech
(626) 395-2543
cummings_at_[hidden]
 

> -----Original Message-----
> From: blitz-dev-bounces_at_[hidden]
> [mailto:blitz-dev-bounces_at_[hidden]] On Behalf Of Derrick Bass
> Sent: Sunday, July 27, 2003 2:15 PM
> To: blitz-dev_at_[hidden]
> Subject: [Blitz-dev] Using blitz with "user" defined classes
>
>
> 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
>
>
> _______________________________________________
> Blitz-dev mailing list
> Blitz-dev_at_[hidden]
> http://www.oonumerics.org/mailman/listinfo.cgi> /blitz-dev
>