--- deliantra/server/include/util.h 2010/04/29 21:21:34 1.104 +++ deliantra/server/include/util.h 2010/04/30 20:43:18 1.105 @@ -57,14 +57,16 @@ // use C0X decltype for auto declarations until ISO C++ sanctifies them (if ever) #define auto(var,expr) decltype(expr) var = (expr) -// could use the sizeof (arr) /( sizeof (arr [0]) here, but C++ is -// much more obfuscated... :) - +#if cplusplus_does_not_suck +// does not work for local types (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2657.htm) template -inline int array_length (const T (&arr)[N]) +static inline int array_length (const T (&arr)[N]) { return N; } +#else +#define array_length(name) (sizeof (name) / sizeof (name [0])) +#endif // very ugly macro that basically declares and initialises a variable // that is in scope for the next statement only @@ -123,6 +125,10 @@ { return expect_false (val < 0) ? - ((-val + (div - 1) / 2) / div) : (val + div / 2) / div; } + +template<> inline float div (float val, float div) { return val / div; } +template<> inline double div (double val, double div) { return val / div; } + // div, round-up template static inline T div_ru (T val, T div) {