From 4350c1e0f72f9d22fc3ed1b16ce21518681aaeb1 Mon Sep 17 00:00:00 2001 From: Peter Boyle Date: Fri, 15 May 2015 11:42:03 +0100 Subject: [PATCH] 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 --- lib/math/Grid_math_peek.h | 74 +++++++++++++-------------------------- 1 file changed, 25 insertions(+), 49 deletions(-) diff --git a/lib/math/Grid_math_peek.h b/lib/math/Grid_math_peek.h index b76fa84d..5c8d4a93 100644 --- a/lib/math/Grid_math_peek.h +++ b/lib/math/Grid_math_peek.h @@ -13,28 +13,22 @@ namespace Grid { //template inline RealD peekIndex(const RealD arg) { return arg;} // Scalar peek, no indices -template inline - auto peekIndex(const iScalar &arg) -> - typename std::enable_if,Level>::value, // Index matches - iScalar >::type // return scalar +template::TensorLevel == Level >::type * =nullptr> inline + auto peekIndex(const iScalar &arg) -> iScalar { return arg; } // Vector peek, one index -template inline - auto peekIndex(const iVector &arg,int i) -> - typename std::enable_if,Level>::value, // Index matches - iScalar >::type // return scalar +template::TensorLevel == Level >::type * =nullptr> inline + auto peekIndex(const iVector &arg,int i) -> iScalar // Index matches { iScalar ret; // return scalar ret._internal = arg._internal[i]; return ret; } // Matrix peek, two indices -template inline - auto peekIndex(const iMatrix &arg,int i,int j) -> - typename std::enable_if,Level>::value, // Index matches - iScalar >::type // return scalar +template::TensorLevel == Level >::type * =nullptr> inline + auto peekIndex(const iMatrix &arg,int i,int j) -> iScalar { iScalar ret; // return scalar ret._internal = arg._internal[i][j]; @@ -45,38 +39,30 @@ template inline // No match peek for scalar,vector,matrix must forward on either 0,1,2 args. Must have 9 routines with notvalue ///////////// // scalar -template inline - auto peekIndex(const iScalar &arg) -> // Scalar 0 index - typename std::enable_if,Level>::notvalue, // Index does NOT match - iScalar(arg._internal))> >::type +template::TensorLevel != Level >::type * =nullptr> inline + auto peekIndex(const iScalar &arg) -> iScalar(arg._internal))> { iScalar(arg._internal))> ret; ret._internal= peekIndex(arg._internal); return ret; } -template inline - auto peekIndex(const iScalar &arg,int i) -> // Scalar 1 index - typename std::enable_if,Level>::notvalue, // Index does NOT match - iScalar(arg._internal,i))> >::type +template::TensorLevel != Level >::type * =nullptr> inline + auto peekIndex(const iScalar &arg,int i) -> iScalar(arg._internal,i))> { iScalar(arg._internal,i))> ret; ret._internal=peekIndex(arg._internal,i); return ret; } -template inline - auto peekIndex(const iScalar &arg,int i,int j) -> // Scalar, 2 index - typename std::enable_if,Level>::notvalue, // Index does NOT match - iScalar(arg._internal,i,j))> >::type +template::TensorLevel != Level >::type * =nullptr> inline + auto peekIndex(const iScalar &arg,int i,int j) -> iScalar(arg._internal,i,j))> { iScalar(arg._internal,i,j))> ret; ret._internal=peekIndex(arg._internal,i,j); return ret; } // vector -template inline -auto peekIndex(const iVector &arg) -> - typename std::enable_if,Level>::notvalue, // Index does not match - iVector(arg._internal[0])),N> >::type +template::TensorLevel != Level >::type * =nullptr> inline +auto peekIndex(const iVector &arg) -> iVector(arg._internal[0])),N> { iVector(arg._internal[0])),N> ret; for(int ii=0;ii &arg) -> } return ret; } -template inline - auto peekIndex(const iVector &arg,int i) -> - typename std::enable_if,Level>::notvalue, // Index does not match - iVector(arg._internal[0],i)),N> >::type +template::TensorLevel != Level >::type * =nullptr> inline + auto peekIndex(const iVector &arg,int i) -> iVector(arg._internal[0],i)),N> { iVector(arg._internal[0],i)),N> ret; for(int ii=0;ii inline } return ret; } -template inline - auto peekIndex(const iVector &arg,int i,int j) -> - typename std::enable_if,Level>::notvalue, // Index does not match - iVector(arg._internal[0],i,j)),N> >::type +template::TensorLevel != Level >::type * =nullptr> inline + auto peekIndex(const iVector &arg,int i,int j) -> iVector(arg._internal[0],i,j)),N> { iVector(arg._internal[0],i,j)),N> ret; for(int ii=0;ii inline return ret; } // matrix -template inline -auto peekIndex(const iMatrix &arg) -> - typename std::enable_if,Level>::notvalue, // Index does not match - iMatrix(arg._internal[0][0])),N> >::type +template::TensorLevel != Level >::type * =nullptr> inline +auto peekIndex(const iMatrix &arg) -> iMatrix(arg._internal[0][0])),N> { iMatrix(arg._internal[0][0])),N> ret; for(int ii=0;ii &arg) -> }} return ret; } -template inline - auto peekIndex(const iMatrix &arg,int i) -> - typename std::enable_if,Level>::notvalue, // Index does not match - iMatrix(arg._internal[0],i)),N> >::type +template::TensorLevel != Level >::type * =nullptr> inline + auto peekIndex(const iMatrix &arg,int i) -> iMatrix(arg._internal[0][0],i)),N> { - iMatrix(arg._internal[0],i)),N> ret; + iMatrix(arg._internal[0][0],i)),N> ret; for(int ii=0;ii(arg._internal[ii][jj],i); }} return ret; } -template inline - auto peekIndex(const iMatrix &arg,int i,int j) -> - typename std::enable_if,Level>::notvalue, // Index does not match - iMatrix(arg._internal[0][0],i,j)),N> >::type +template::TensorLevel != Level >::type * =nullptr> inline + auto peekIndex(const iMatrix &arg,int i,int j) -> iMatrix(arg._internal[0][0],i,j)),N> { iMatrix(arg._internal[0][0],i,j)),N> ret; for(int ii=0;ii