#include <type_traits>
template<typename Scalar>
class Complex
{
Scalar re, im;
public:
Complex(Scalar re, Scalar im)
{
static_assert(is_arithmetic<Scalar>(),
"complex is supported only for arithmetic types");
this->re = re;
this->im = im;
}
};
int main()
{
Complex<int> ci(5, 6);
Complex<string> cs("A", "B");
}
Compilation error is:
|In instantiation of 'Complex<Scalar>::Complex(Scalar, Scalar) [with Scalar =
std::basic_string<char>]':|
|error: static assertion failed: complex is supported only for arithmetic types|
Actually, there is no instantiation of Complex<Scalar> with <char> at all. What's the problem here?