mirror of
https://github.com/paboyle/Grid.git
synced 2024-11-10 15:55:37 +00:00
More elegant to do boolean logic inside the enable_if construct
Should have done that from the beginning and should move this into a global edit
This commit is contained in:
parent
af6e8f7829
commit
a26fdab719
@ -13,28 +13,22 @@ namespace Grid {
|
|||||||
//template<int Level> inline RealD peekIndex(const RealD arg) { return arg;}
|
//template<int Level> inline RealD peekIndex(const RealD arg) { return arg;}
|
||||||
|
|
||||||
// Scalar peek, no indices
|
// Scalar peek, no indices
|
||||||
template<int Level,class vtype> inline
|
template<int Level,class vtype,typename std::enable_if< iScalar<vtype>::TensorLevel == Level >::type * =nullptr> inline
|
||||||
auto peekIndex(const iScalar<vtype> &arg) ->
|
auto peekIndex(const iScalar<vtype> &arg) -> iScalar<vtype>
|
||||||
typename std::enable_if<matchGridTensorIndex<iScalar<vtype>,Level>::value, // Index matches
|
|
||||||
iScalar<vtype> >::type // return scalar
|
|
||||||
{
|
{
|
||||||
return arg;
|
return arg;
|
||||||
}
|
}
|
||||||
// Vector peek, one index
|
// Vector peek, 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
|
||||||
auto peekIndex(const iVector<vtype,N> &arg,int i) ->
|
auto peekIndex(const iVector<vtype,N> &arg,int i) -> iScalar<vtype> // Index matches
|
||||||
typename std::enable_if<matchGridTensorIndex<iVector<vtype,N>,Level>::value, // Index matches
|
|
||||||
iScalar<vtype> >::type // return scalar
|
|
||||||
{
|
{
|
||||||
iScalar<vtype> ret; // return scalar
|
iScalar<vtype> ret; // return scalar
|
||||||
ret._internal = arg._internal[i];
|
ret._internal = arg._internal[i];
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
// Matrix peek, two indices
|
// Matrix peek, 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
|
||||||
auto peekIndex(const iMatrix<vtype,N> &arg,int i,int j) ->
|
auto peekIndex(const iMatrix<vtype,N> &arg,int i,int j) -> iScalar<vtype>
|
||||||
typename std::enable_if<matchGridTensorIndex<iMatrix<vtype,N>,Level>::value, // Index matches
|
|
||||||
iScalar<vtype> >::type // return scalar
|
|
||||||
{
|
{
|
||||||
iScalar<vtype> ret; // return scalar
|
iScalar<vtype> ret; // return scalar
|
||||||
ret._internal = arg._internal[i][j];
|
ret._internal = arg._internal[i][j];
|
||||||
@ -45,38 +39,30 @@ template<int Level,class vtype,int N> inline
|
|||||||
// No match peek for scalar,vector,matrix must forward on either 0,1,2 args. Must have 9 routines with notvalue
|
// No match peek 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
|
||||||
auto peekIndex(const iScalar<vtype> &arg) -> // Scalar 0 index
|
auto peekIndex(const iScalar<vtype> &arg) -> iScalar<decltype(peekIndex<Level>(arg._internal))>
|
||||||
typename std::enable_if<matchGridTensorIndex<iScalar<vtype>,Level>::notvalue, // Index does NOT match
|
|
||||||
iScalar<decltype(peekIndex<Level>(arg._internal))> >::type
|
|
||||||
{
|
{
|
||||||
iScalar<decltype(peekIndex<Level>(arg._internal))> ret;
|
iScalar<decltype(peekIndex<Level>(arg._internal))> ret;
|
||||||
ret._internal= peekIndex<Level>(arg._internal);
|
ret._internal= peekIndex<Level>(arg._internal);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
template<int Level,class vtype> inline
|
template<int Level,class vtype, typename std::enable_if< iScalar<vtype>::TensorLevel != Level >::type * =nullptr> inline
|
||||||
auto peekIndex(const iScalar<vtype> &arg,int i) -> // Scalar 1 index
|
auto peekIndex(const iScalar<vtype> &arg,int i) -> iScalar<decltype(peekIndex<Level>(arg._internal,i))>
|
||||||
typename std::enable_if<matchGridTensorIndex<iScalar<vtype>,Level>::notvalue, // Index does NOT match
|
|
||||||
iScalar<decltype(peekIndex<Level>(arg._internal,i))> >::type
|
|
||||||
{
|
{
|
||||||
iScalar<decltype(peekIndex<Level>(arg._internal,i))> ret;
|
iScalar<decltype(peekIndex<Level>(arg._internal,i))> ret;
|
||||||
ret._internal=peekIndex<Level>(arg._internal,i);
|
ret._internal=peekIndex<Level>(arg._internal,i);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
template<int Level,class vtype> inline
|
template<int Level,class vtype, typename std::enable_if< iScalar<vtype>::TensorLevel != Level >::type * =nullptr> inline
|
||||||
auto peekIndex(const iScalar<vtype> &arg,int i,int j) -> // Scalar, 2 index
|
auto peekIndex(const iScalar<vtype> &arg,int i,int j) -> iScalar<decltype(peekIndex<Level>(arg._internal,i,j))>
|
||||||
typename std::enable_if<matchGridTensorIndex<iScalar<vtype>,Level>::notvalue, // Index does NOT match
|
|
||||||
iScalar<decltype(peekIndex<Level>(arg._internal,i,j))> >::type
|
|
||||||
{
|
{
|
||||||
iScalar<decltype(peekIndex<Level>(arg._internal,i,j))> ret;
|
iScalar<decltype(peekIndex<Level>(arg._internal,i,j))> ret;
|
||||||
ret._internal=peekIndex<Level>(arg._internal,i,j);
|
ret._internal=peekIndex<Level>(arg._internal,i,j);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
// 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
|
||||||
auto peekIndex(const iVector<vtype,N> &arg) ->
|
auto peekIndex(const iVector<vtype,N> &arg) -> iVector<decltype(peekIndex<Level>(arg._internal[0])),N>
|
||||||
typename std::enable_if<matchGridTensorIndex<iScalar<vtype>,Level>::notvalue, // Index does not match
|
|
||||||
iVector<decltype(peekIndex<Level>(arg._internal[0])),N> >::type
|
|
||||||
{
|
{
|
||||||
iVector<decltype(peekIndex<Level>(arg._internal[0])),N> ret;
|
iVector<decltype(peekIndex<Level>(arg._internal[0])),N> ret;
|
||||||
for(int ii=0;ii<N;ii++){
|
for(int ii=0;ii<N;ii++){
|
||||||
@ -84,10 +70,8 @@ auto peekIndex(const iVector<vtype,N> &arg) ->
|
|||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
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
|
||||||
auto peekIndex(const iVector<vtype,N> &arg,int i) ->
|
auto peekIndex(const iVector<vtype,N> &arg,int i) -> iVector<decltype(peekIndex<Level>(arg._internal[0],i)),N>
|
||||||
typename std::enable_if<matchGridTensorIndex<iVector<vtype,N>,Level>::notvalue, // Index does not match
|
|
||||||
iVector<decltype(peekIndex<Level>(arg._internal[0],i)),N> >::type
|
|
||||||
{
|
{
|
||||||
iVector<decltype(peekIndex<Level>(arg._internal[0],i)),N> ret;
|
iVector<decltype(peekIndex<Level>(arg._internal[0],i)),N> ret;
|
||||||
for(int ii=0;ii<N;ii++){
|
for(int ii=0;ii<N;ii++){
|
||||||
@ -95,10 +79,8 @@ template<int Level,class vtype,int N> inline
|
|||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
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
|
||||||
auto peekIndex(const iVector<vtype,N> &arg,int i,int j) ->
|
auto peekIndex(const iVector<vtype,N> &arg,int i,int j) -> iVector<decltype(peekIndex<Level>(arg._internal[0],i,j)),N>
|
||||||
typename std::enable_if<matchGridTensorIndex<iVector<vtype,N>,Level>::notvalue, // Index does not match
|
|
||||||
iVector<decltype(peekIndex<Level>(arg._internal[0],i,j)),N> >::type
|
|
||||||
{
|
{
|
||||||
iVector<decltype(peekIndex<Level>(arg._internal[0],i,j)),N> ret;
|
iVector<decltype(peekIndex<Level>(arg._internal[0],i,j)),N> ret;
|
||||||
for(int ii=0;ii<N;ii++){
|
for(int ii=0;ii<N;ii++){
|
||||||
@ -107,10 +89,8 @@ template<int Level,class vtype,int N> inline
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
// 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
|
||||||
auto peekIndex(const iMatrix<vtype,N> &arg) ->
|
auto peekIndex(const iMatrix<vtype,N> &arg) -> iMatrix<decltype(peekIndex<Level>(arg._internal[0][0])),N>
|
||||||
typename std::enable_if<matchGridTensorIndex<iScalar<vtype>,Level>::notvalue, // Index does not match
|
|
||||||
iMatrix<decltype(peekIndex<Level>(arg._internal[0][0])),N> >::type
|
|
||||||
{
|
{
|
||||||
iMatrix<decltype(peekIndex<Level>(arg._internal[0][0])),N> ret;
|
iMatrix<decltype(peekIndex<Level>(arg._internal[0][0])),N> ret;
|
||||||
for(int ii=0;ii<N;ii++){
|
for(int ii=0;ii<N;ii++){
|
||||||
@ -119,22 +99,18 @@ auto peekIndex(const iMatrix<vtype,N> &arg) ->
|
|||||||
}}
|
}}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
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
|
||||||
auto peekIndex(const iMatrix<vtype,N> &arg,int i) ->
|
auto peekIndex(const iMatrix<vtype,N> &arg,int i) -> iMatrix<decltype(peekIndex<Level>(arg._internal[0][0],i)),N>
|
||||||
typename std::enable_if<matchGridTensorIndex<iMatrix<vtype,N>,Level>::notvalue, // Index does not match
|
|
||||||
iMatrix<decltype(peekIndex<Level>(arg._internal[0],i)),N> >::type
|
|
||||||
{
|
{
|
||||||
iMatrix<decltype(peekIndex<Level>(arg._internal[0],i)),N> ret;
|
iMatrix<decltype(peekIndex<Level>(arg._internal[0][0],i)),N> ret;
|
||||||
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++){
|
||||||
ret._internal[ii][jj]=peekIndex<Level>(arg._internal[ii][jj],i);
|
ret._internal[ii][jj]=peekIndex<Level>(arg._internal[ii][jj],i);
|
||||||
}}
|
}}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
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
|
||||||
auto peekIndex(const iMatrix<vtype,N> &arg,int i,int j) ->
|
auto peekIndex(const iMatrix<vtype,N> &arg,int i,int j) -> iMatrix<decltype(peekIndex<Level>(arg._internal[0][0],i,j)),N>
|
||||||
typename std::enable_if<matchGridTensorIndex<iMatrix<vtype,N>,Level>::notvalue, // Index does not match
|
|
||||||
iMatrix<decltype(peekIndex<Level>(arg._internal[0][0],i,j)),N> >::type
|
|
||||||
{
|
{
|
||||||
iMatrix<decltype(peekIndex<Level>(arg._internal[0][0],i,j)),N> ret;
|
iMatrix<decltype(peekIndex<Level>(arg._internal[0][0],i,j)),N> ret;
|
||||||
for(int ii=0;ii<N;ii++){
|
for(int ii=0;ii<N;ii++){
|
||||||
|
Loading…
Reference in New Issue
Block a user