![]() |
Blitz Devel : |
From: Peter Kümmel (syntheticpp_at_[hidden])
Date: 2005-06-21 09:39:08
Hello,
here are some suggestions to the macro related code.
The text is attached as file because line breaks
would make it unreadable.
Best regards,
Peter
1. Several macros for user-defined functions in newet-macros.h
implements already existing code, e.g.
#define BZ_DECLARE_FUNCTION(name) \
template <typename P_numtype> \
struct name ## _impl { \
typedef P_numtype T_numtype; \
static inline T_numtype apply(P_numtype x) { return name(x); } \
template <typename T> \
static void prettyPrint(BZ_STD_SCOPE(string) &str, \
prettyPrintFormat& format, \
const T& a) { \
str += #name; \
str += "("; \
a.prettyPrint(str,format); \
str += ")"; \
} \
}; \
could be replaced with
#define BZ_DECLARE_FUNCTION(name) \
BZ_DEFINE_UNARY_FUNC(name ## _impl, name); \
BZ_DECLARE_ARRAY_ET_UNARY(name,name ## _impl);
Because off the 7 macros,
BZ_DECLARE_FUNCTION (name)
BZ_DECLARE_FUNCTION2 (name)
BZ_DECLARE_FUNCTION2_RET (name, return_type)
BZ_DECLARE_FUNCTION2_SCALAR (name, sca)
BZ_DECLARE_FUNCTION3 (name)
BZ_DECLARE_FUNCTION3_RET (name, return_type)
BZ_DECLARE_FUNCTION_RET (name,return_type)
the file could shrink about 30%. Maybe also a different file is
a better place for these macros.
2. Splitting /blitz/funcs.h into two files makes the code more readable,
especially if you want to add some new macros.
Why not move all the macro definitions to a new file.,
e.g. func-def-macros.h? Here a overview of the mentioned macros:
/*
BZ_DEFINE_UNARY_FUNC (name,fun) : A -> A
BZ_DEFINE_UNARY_FUNC_RET (name,fun,ret) : A -> B
BZ_DEFINE_BINARY_FUNC (name,fun) : (A,B) -> promote(A,B)
BZ_DEFINE_BINARY_FUNC_RET (name,fun,ret) : (A,B) -> C
BZ_DEFINE_TERNARY_FUNC (name,fun) : (A,B,C) -> promote(A,B,D) //TODO:promote
BZ_DEFINE_TERNARY_FUNC_RET (name,fun,ret) : (A,B,C) -> D
BZ_DEFINE_QUADRUPLE_FUNC (name,fun) : (A,B,C,D) -> promote(A,B,C,D) //TODO: promote
BZ_DEFINE_QUADRUPLE_FUNC_RET(name,fun,ret) : (A,B,C,D) -> F
std::complex<T> spezific macros:
BZ_DEFINE_UNARY_CFUNC (name,fun) : complex<A> -> complex<A>
BZ_DEFINE_UNARY_CFUNC2 (name,fun) : complex<A> -> A
BZ_DEFINE_BINARY_CFUNC (name,fun) : (complex<A>,complex<A>) -> complex<A>
BZ_DEFINE_BINARY_CFUNC2 (name,fun) : (A,A) -> complex<A>
*/
3. The naming of the _CFUNC macros seems not to be consistent:
Does BZ_DEFINE_BINARY_CFUNC2 not looks like: (complex<A>,complex<A>) -> A?