1
0
mirror of https://github.com/paboyle/Grid.git synced 2024-09-20 17:25:37 +01:00

More elegant enable_if

This commit is contained in:
Peter Boyle 2015-05-15 11:42:51 +01:00
parent 4350c1e0f7
commit 3e3a8dc0c0

View File

@ -7,23 +7,20 @@ namespace Grid {
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
// Scalar poke // Scalar poke
template<int Level,class vtype> inline template<int Level,class vtype,typename std::enable_if< iScalar<vtype>::TensorLevel == Level >::type * =nullptr> inline
void pokeIndex(iScalar<vtype> &ret, void pokeIndex(iScalar<vtype> &ret, const iScalar<vtype> &arg)
const typename std::enable_if<matchGridTensorIndex<iScalar<vtype>,Level>::value,iScalar<vtype> >::type &arg)
{ {
ret._internal = arg._internal; ret._internal = arg._internal;
} }
// Vector poke, one index // Vector poke, one index
template<int Level,class vtype,int N> inline template<int Level,class vtype,int N,typename std::enable_if< iScalar<vtype>::TensorLevel == Level >::type * =nullptr> inline
void pokeIndex(iVector<vtype,N> &ret, void pokeIndex(iVector<vtype,N> &ret, const iScalar<vtype> &arg,int i)
const typename std::enable_if<matchGridTensorIndex<iVector<vtype,N>,Level>::value,iScalar<vtype> >::type &arg,int i)
{ {
ret._internal[i] = arg._internal; ret._internal[i] = arg._internal;
} }
// Vector poke, two indices // Vector poke, two indices
template<int Level,class vtype,int N> inline template<int Level,class vtype,int N,typename std::enable_if< iScalar<vtype>::TensorLevel == Level >::type * =nullptr> inline
void pokeIndex(iMatrix<vtype,N> &ret, void pokeIndex(iMatrix<vtype,N> &ret, const iScalar<vtype> &arg,int i,int j)
const typename std::enable_if<matchGridTensorIndex<iMatrix<vtype,N>,Level>::value,iScalar<vtype> >::type &arg,int i,int j)
{ {
ret._internal[i][j] = arg._internal; ret._internal[i][j] = arg._internal;
} }
@ -32,55 +29,41 @@ template<int Level,class vtype,int N> inline
// No match poke for scalar,vector,matrix must forward on either 0,1,2 args. Must have 9 routines with notvalue // No match poke for scalar,vector,matrix must forward on either 0,1,2 args. Must have 9 routines with notvalue
///////////// /////////////
// scalar // scalar
template<int Level,class vtype> inline template<int Level,class vtype,typename std::enable_if< iScalar<vtype>::TensorLevel != Level >::type * =nullptr> inline
void pokeIndex(iScalar<vtype> &ret, void pokeIndex(iScalar<vtype> &ret, const iScalar<decltype(peekIndex<Level>(ret._internal))> &arg)
const typename std::enable_if<matchGridTensorIndex<iScalar<vtype>,Level>::notvalue,iScalar<decltype(peekIndex<Level>(ret._internal))> >::type &arg)
{ {
pokeIndex<Level>(ret._internal,arg._internal); pokeIndex<Level>(ret._internal,arg._internal);
} }
template<int Level,class vtype> inline template<int Level,class vtype,typename std::enable_if< iScalar<vtype>::TensorLevel != Level >::type * =nullptr> inline
void pokeIndex(iScalar<vtype> &ret, void pokeIndex(iScalar<vtype> &ret, const iScalar<decltype(peekIndex<Level>(ret._internal,0))> &arg, int i)
const typename std::enable_if<matchGridTensorIndex<iScalar<vtype>,Level>::notvalue,iScalar<decltype(peekIndex<Level>(ret._internal,0))> >::type &arg,
int i)
{ {
pokeIndex<Level>(ret._internal,arg._internal,i); pokeIndex<Level>(ret._internal,arg._internal,i);
} }
template<int Level,class vtype> inline template<int Level,class vtype,typename std::enable_if< iScalar<vtype>::TensorLevel != Level >::type * =nullptr> inline
void pokeIndex(iScalar<vtype> &ret, void pokeIndex(iScalar<vtype> &ret, const iScalar<decltype(peekIndex<Level>(ret._internal,0,0))> &arg,int i,int j)
const typename std::enable_if<matchGridTensorIndex<iScalar<vtype>,Level>::notvalue,iScalar<decltype(peekIndex<Level>(ret._internal,0,0))> >::type &arg,
int i,int j)
{ {
pokeIndex<Level>(ret._internal,arg._internal,i,j); pokeIndex<Level>(ret._internal,arg._internal,i,j);
} }
// Vector // Vector
template<int Level,class vtype,int N> inline template<int Level,class vtype,int N,typename std::enable_if< iScalar<vtype>::TensorLevel != Level >::type * =nullptr> inline
void pokeIndex(iVector<vtype,N> &ret, void pokeIndex(iVector<vtype,N> &ret, iVector<decltype(peekIndex<Level>(ret._internal)),N> &arg)
const typename std::enable_if<matchGridTensorIndex<iVector<vtype,N>,Level>::notvalue,iVector<decltype(peekIndex<Level>(ret._internal)),N> >::type &arg)
{ {
for(int ii=0;ii<N;ii++){ for(int ii=0;ii<N;ii++){
pokeIndex<Level>(ret._internal[ii],arg._internal[ii]); pokeIndex<Level>(ret._internal[ii],arg._internal[ii]);
} }
} }
template<int Level,class vtype,int N> inline template<int Level,class vtype,int N,typename std::enable_if< iScalar<vtype>::TensorLevel != Level >::type * =nullptr> inline
void pokeIndex(iVector<vtype,N> &ret, void pokeIndex(iVector<vtype,N> &ret, const iVector<decltype(peekIndex<Level>(ret._internal,0)),N> &arg,int i)
const typename std::enable_if<matchGridTensorIndex<iVector<vtype,N>,Level>::notvalue,iVector<decltype(peekIndex<Level>(ret._internal,0)),N> >::type &arg,
int i)
{ {
for(int ii=0;ii<N;ii++){ for(int ii=0;ii<N;ii++){
pokeIndex<Level>(ret._internal[ii],arg._internal[ii],i); pokeIndex<Level>(ret._internal[ii],arg._internal[ii],i);
} }
} }
template<int Level,class vtype,int N> inline template<int Level,class vtype,int N,typename std::enable_if< iScalar<vtype>::TensorLevel != Level >::type * =nullptr> inline
void pokeIndex(iVector<vtype,N> &ret, void pokeIndex(iVector<vtype,N> &ret, const iVector<decltype(peekIndex<Level>(ret._internal,0,0)),N> &arg,int i,int j)
const typename std::enable_if<matchGridTensorIndex<iVector<vtype,N>,Level>::notvalue,iVector<decltype(peekIndex<Level>(ret._internal,0,0)),N> >::type &arg,
int i,int j)
{ {
for(int ii=0;ii<N;ii++){ for(int ii=0;ii<N;ii++){
pokeIndex<Level>(ret._internal[ii],arg._internal[ii],i,j); pokeIndex<Level>(ret._internal[ii],arg._internal[ii],i,j);
@ -88,32 +71,24 @@ template<int Level,class vtype,int N> inline
} }
// Matrix // Matrix
template<int Level,class vtype,int N> inline template<int Level,class vtype,int N,typename std::enable_if< iScalar<vtype>::TensorLevel != Level >::type * =nullptr> inline
void pokeIndex(iMatrix<vtype,N> &ret, void pokeIndex(iMatrix<vtype,N> &ret, const iMatrix<decltype(peekIndex<Level>(ret._internal)),N> &arg)
const typename std::enable_if<matchGridTensorIndex<iMatrix<vtype,N>,Level>::notvalue,iMatrix<decltype(peekIndex<Level>(ret._internal)),N> >::type &arg)
{ {
for(int ii=0;ii<N;ii++){ for(int ii=0;ii<N;ii++){
for(int jj=0;jj<N;jj++){ for(int jj=0;jj<N;jj++){
pokeIndex<Level>(ret._internal[ii][jj],arg._internal[ii][jj]); pokeIndex<Level>(ret._internal[ii][jj],arg._internal[ii][jj]);
}} }}
} }
template<int Level,class vtype,int N> inline template<int Level,class vtype,int N,typename std::enable_if< iScalar<vtype>::TensorLevel != Level >::type * =nullptr> inline
void pokeIndex(iMatrix<vtype,N> &ret, void pokeIndex(iMatrix<vtype,N> &ret, const iMatrix<decltype(peekIndex<Level>(ret._internal,0)),N> &arg,int i)
const typename std::enable_if<matchGridTensorIndex<iMatrix<vtype,N>,Level>::notvalue,iMatrix<decltype(peekIndex<Level>(ret._internal,0)),N> >::type &arg,
int i)
{ {
for(int ii=0;ii<N;ii++){ for(int ii=0;ii<N;ii++){
for(int jj=0;jj<N;jj++){ for(int jj=0;jj<N;jj++){
pokeIndex<Level>(ret._internal[ii][jj],arg._internal[ii][jj],i); pokeIndex<Level>(ret._internal[ii][jj],arg._internal[ii][jj],i);
}} }}
} }
template<int Level,class vtype,int N> inline template<int Level,class vtype,int N,typename std::enable_if< iScalar<vtype>::TensorLevel != Level >::type * =nullptr> inline
void pokeIndex(iMatrix<vtype,N> &ret, void pokeIndex(iMatrix<vtype,N> &ret, const iMatrix<decltype(peekIndex<Level>(ret._internal,0,0)),N> &arg, int i,int j)
const typename std::enable_if<matchGridTensorIndex<iMatrix<vtype,N>,Level>::notvalue,iMatrix<decltype(peekIndex<Level>(ret._internal,0,0)),N> >::type &arg,
int i,int j)
{ {
for(int ii=0;ii<N;ii++){ for(int ii=0;ii<N;ii++){
for(int jj=0;jj<N;jj++){ for(int jj=0;jj<N;jj++){