I have a class A
templated with a Scalar
which can be real- or complex-valued. It has a method realPart
which is supposed to return the re
This can be done with a simple is_complex
trait and SFINAE:
template struct is_complex : std::false_type {};
template struct is_complex> : std::true_type {};
template
class A {
public:
A(const Scalar z) : z_(z)
{ }
template{}>* = nullptr>
Scalar realPart()
{
return z_.real();
}
template{}>* = nullptr>
Scalar realPart()
{
return z_;
}
private:
Scalar z_;
};