1 #ifndef TIL_NUMERIC_ARRAY_OPERATORS_H 2 #define TIL_NUMERIC_ARRAY_OPERATORS_H 24 #define TIL_DEFINE_TEMPLATE_OP(name, op) \ 25 template < typename T1, typename T2, typename TRes, std::size_t D > \ 26 struct name <numeric_array<T1,D>, numeric_array<T2,D>, TRes > \ 27 : public std::binary_function<const numeric_array<T1,D> &, const numeric_array<T2,D> &, TRes > \ 29 typedef std::binary_function<const numeric_array<T1,D> &, const numeric_array<T2,D> &, TRes > Base; \ 30 typedef typename Base::first_argument_type first_argument_type; \ 31 typedef typename Base::second_argument_type second_argument_type; \ 32 typedef typename Base::result_type result_type; \ 33 TRes operator()(first_argument_type x, second_argument_type y) \ 35 typedef typename value_type_of<TRes>::type value_type; \ 37 for (std::size_t i = 0; i < D; ++i) \ 38 res[i] = static_cast<value_type>(x[i]) op static_cast<value_type>(y[i]); \ 42 template < typename T, typename TRes, std::size_t D > \ 43 struct name <T, numeric_array<T,D>, TRes > \ 44 : public std::binary_function<T, const numeric_array<T,D> &, TRes > \ 46 typedef std::binary_function<T, const numeric_array<T,D> &, TRes > Base; \ 47 typedef typename Base::first_argument_type first_argument_type; \ 48 typedef typename Base::second_argument_type second_argument_type; \ 49 typedef typename Base::result_type result_type; \ 50 TRes operator()(first_argument_type x, second_argument_type y) \ 53 for (std::size_t i = 0; i < D; ++i) res[i] = x op y[i]; \ 57 template < typename T, typename TRes, std::size_t D > \ 58 struct name <numeric_array<T,D>, T, TRes > \ 59 : public std::binary_function<const numeric_array<T,D> &, T, TRes > \ 61 typedef std::binary_function<const numeric_array<T,D> &, T, TRes > Base; \ 62 typedef typename Base::first_argument_type first_argument_type; \ 63 typedef typename Base::second_argument_type second_argument_type; \ 64 typedef typename Base::result_type result_type; \ 65 TRes operator()(first_argument_type x, second_argument_type y) \ 68 for (std::size_t i = 0; i < D; ++i) res[i] = x[i] op y; \ 79 #undef TIL_DEFINE_TEMPLATE_OP 88 template <
typename T1,
typename T2, std::
size_t D >
90 :
public std::binary_function<numeric_array<T1,D> &, const numeric_array<T2,D> &, void>
95 void operator()(first_argument_type x, second_argument_type y)
97 for (std::size_t i = 0; i < D; ++i) x[i] = y[i];
126 #define TIL_OPERATOR(op, func) \ 127 template < typename T, std::size_t D > \ 130 operator op (const numeric_array<T,D> & x, const numeric_array<T,D> & y) \ 132 return func <numeric_array<T,D>,numeric_array<T,D>,numeric_array<T,D> >() (x,y); \ 154 #define TIL_OPERATOR(op, func) \ 155 template < typename T , std::size_t D > \ 158 operator op (const numeric_array<T,D> & x, T y) \ 160 return func <numeric_array<T,D>,T,numeric_array<T,D> >()(x,y); \ 162 template < typename T, std::size_t D > \ 165 operator op (T y, const numeric_array<T,D> & x) \ 167 return func <T,numeric_array<T,D>,numeric_array<T,D> >()(y,x); \ 187 #define TIL_BOOL_VALUE_OPERATOR(opname, op) \ 188 template < typename T1, typename T2, std::size_t D > \ 189 inline bool opname (const numeric_array<T1,D> & x, \ 190 const numeric_array<T2,D> & y) \ 192 for (std::size_t i = 0; i < D; ++i) \ 194 if (!(x[i] op y[i])) return false; \ 198 template < typename T, std::size_t D > \ 199 inline bool opname (const numeric_array<T,D> & x, \ 200 typename boost::call_traits<T>::param_type y) \ 202 for (std::size_t i = 0; i < D; ++i) \ 204 if (!(x[i] op y)) return false; \ 222 #undef TIL_BOOL_VALUE_OPERATOR 233 template < typename T, std::size_t D > \ 234 bool operator op (const numeric_array<T,D> & x, const numeric_array<T,D> & y) \ 236 return x.do_not_use_these_operators(); \ #define TIL_DEFINE_TEMPLATE_OP(name, op)
Belongs to package Box Do not include directly, include til/Box.h instead.
TIL_OPERATOR(+, functor::Add)
std::binary_function< numeric_array< T1, D > &, const numeric_array< T2, D > &, void > Base
TIL_BOOL_VALUE_OPERATOR(operator==,==)
Base::first_argument_type first_argument_type
Base::second_argument_type second_argument_type
void operator()(first_argument_type x, second_argument_type y)