distinguish complex or real ITensor in compiling

+1 vote

I wonder if there is a way to distinguish whether an ITensor contains real or complex elements in compiling. I found that I often get a problem of whether to use elt or eltC. For example if I make a function to print the value of a zero-dimension tensor, I will need to use either one of them

void printTensor (ITensor T)
{
cout << elt(T) << endl;
// cout << eltC(T) << endl;
}


and will get an compiling error if I use the wrong one. If would be useful if the type (real or complex) can be automatically determined. I am thinking about something like

void printTensor (ITensor T)
{
constexpr bool is_real = T.something();
if constexpr (is_real)
cout << elt(T) << endl;
else
cout << eltC(T) << endl;
}


Do you think this is possible?

+1 vote
If you want to do the same for a more general kind of tensor, note that there are functions isReal(T) and isComplex(T) you can call on an ITensor T to see if it has purely real elements or has complex elements: http://itensor.org/docs.cgi?vers=cppv3&page=classes/itensor