21 #ifndef _METAPROGRAMS_H_ 22 #define _METAPROGRAMS_H_ 38 template<
int N,
typename T,
typename RT,
typename PlusT,
typename TimesT>
46 return PlusT()(
InnerProduct<N-1,T,RT,PlusT,TimesT>()(v1,v2),
47 TimesT()(v1[N-1],v2[N-1]) );
51 return PlusT()(
InnerProduct<N-1,T,RT,PlusT,TimesT>()(v,x),
57 template<
typename PlusT,
typename T,
typename RT,
typename TimesT>
62 return TimesT()( v1[0], v2[0] );
66 return TimesT()( v[0], x );
72 template<
int N,
typename T,
typename CompareT>
76 std::logical_and<bool>,
77 CompareT >()( v1, v2 );
80 template<
int N,
typename T,
typename CompareT>
84 std::logical_and<bool>,
90 template<
int N,
typename T,
typename ReduceT,
typename TransformT=Identity<T> >
99 T
operator()( T
const * v, TransformT
const& xform )
const 101 return ReduceT()( xform(v,N-1),
Accum<N-1,T,ReduceT,TransformT>()(v,xform) );
105 template<
typename T,
typename ReduceT,
typename TransformT >
106 struct Accum<1,T,ReduceT,TransformT>
110 return TransformT()(v[0]);
122 template<
int N,
typename T>
struct LexLT 126 return doit( v1+N, v2+N );
129 static bool doit(
const T* v1,
const T* v2 )
131 if ( v1[-N] < v2[-N] )
return true;
132 else if ( v1[-N] > v2[-N] )
return false;
138 template<
typename T>
struct LexLT<1,T>
144 static bool doit(
const T* v1,
const T* v2 )
146 if ( v1[-1] < v2[-1] )
return true;
153 template<
int N,
typename T,
typename FunctorT>
struct Transform 157 v[N-1] = FunctorT()(v[N-1]);
162 v[N-1] = FunctorT()(v[N-1],x);
167 v1[N-1] = FunctorT()(v1[N-1],v2[N-1]);
172 template<
typename T,
typename FunctorT>
struct Transform<1,T,FunctorT>
176 v[0] = FunctorT()(v[0]);
180 v[0] = FunctorT()(v[0],x);
184 v1[0] = FunctorT()(v1[0],v2[0]);
191 template<
int N,
int P>
struct Pow 193 static const int value = N *
Pow<N,P-1>::value;
196 template<
int N>
struct Pow<N,1>
198 static const int value = N;
229 for ( index[N-1]=lo; index[N-1]<hi; ++index[N-1] )
234 void operator()(
int * index,
const int * lo,
const int * hi, OP& op )
const 236 for ( index[N-1]=lo[N-1]; index[N-1]<hi[N-1]; ++index[N-1] )
250 void operator()(
int * index,
const int * lo,
const int * hi, OP& op )
const 262 for ( index[N-1]=lo; index[N-1]<hi; ++index[N-1] )
268 void operator()(
int * index,
const int * lo,
const int * hi, OP& op )
const 270 for ( index[N-1]=lo[N-1]; index[N-1]<hi[N-1]; ++index[N-1] )
285 void operator()(
int * index,
const int * lo,
const int * hi, OP& op )
const 296 template<
int N,
class OP>
struct dterm 300 dterm<N-1,OP>()( op );
305 template<
class OP>
struct dterm<1,OP>
316 #endif // include guard