1
0
mirror of https://github.com/paboyle/Grid.git synced 2024-11-10 07:55:35 +00:00

Pretty syntax

This commit is contained in:
Peter Boyle 2015-05-16 04:37:26 +01:00
parent a19aa9627d
commit 2e4ba02443

View File

@ -35,39 +35,22 @@ inline auto trace(const iScalar<vtype> &arg) -> iScalar<decltype(trace(arg._inte
//////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////
// Trace Specific indices. // Trace Specific indices.
//////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////
/* template<int Level,class vtype,typename std::enable_if< iScalar<vtype>::TensorLevel != Level >::type * =nullptr> inline auto
template<int Level,class vtype> inline traceIndex (const iScalar<vtype> &arg) -> iScalar<decltype(traceIndex<Level>(arg._internal))>
auto traceIndex(const iScalar<vtype> &arg) -> iScalar<decltype(traceIndex<Level>(arg._internal)) >
{
iScalar<decltype(traceIndex<Level>(arg._internal))> ret;
ret._internal = traceIndex<Level>(arg._internal);
return ret;
}
*/
template<int Level,class vtype> inline auto
traceIndex (const iScalar<vtype> &arg) ->
typename
std::enable_if<matchGridTensorIndex<iScalar<vtype>,Level>::notvalue,
iScalar<decltype(traceIndex<Level>(arg._internal))> >::type
{ {
iScalar<decltype(traceIndex<Level>(arg._internal))> ret; iScalar<decltype(traceIndex<Level>(arg._internal))> ret;
ret._internal=traceIndex<Level>(arg._internal); ret._internal=traceIndex<Level>(arg._internal);
return ret; return ret;
} }
template<int Level,class vtype> inline auto template<int Level,class vtype,typename std::enable_if< iScalar<vtype>::TensorLevel == Level >::type * =nullptr> inline auto
traceIndex (const iScalar<vtype> &arg) -> traceIndex (const iScalar<vtype> &arg) -> iScalar<vtype>
typename std::enable_if<matchGridTensorIndex<iScalar<vtype>,Level>::value,
iScalar<vtype> >::type
{ {
return arg; return arg;
} }
// If we hit the right index, return scalar and trace it with no further recursion // If we hit the right index, return scalar and trace it with no further recursion
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 traceIndex(const iMatrix<vtype,N> &arg) -> auto traceIndex(const iMatrix<vtype,N> &arg) -> iScalar<vtype>
typename std::enable_if<matchGridTensorIndex<iScalar<vtype>,Level>::value, // Index matches
iScalar<vtype> >::type // return scalar
{ {
iScalar<vtype> ret; iScalar<vtype> ret;
zeroit(ret._internal); zeroit(ret._internal);
@ -78,10 +61,8 @@ auto traceIndex(const iMatrix<vtype,N> &arg) ->
} }
// not this level, so recurse // not this level, so recurse
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 traceIndex(const iMatrix<vtype,N> &arg) -> auto traceIndex(const iMatrix<vtype,N> &arg) -> iMatrix<decltype(traceIndex<Level>(arg._internal[0][0])),N>
typename std::enable_if<matchGridTensorIndex<iMatrix<vtype,N>,Level>::notvalue,// No index match
iMatrix<decltype(traceIndex<Level>(arg._internal[0][0])),N> >::type // return matrix
{ {
iMatrix<decltype(traceIndex<Level>(arg._internal[0][0])),N> ret; iMatrix<decltype(traceIndex<Level>(arg._internal[0][0])),N> ret;
for(int i=0;i<N;i++){ for(int i=0;i<N;i++){