Why does C++ mandate that complex only be instantiated for float, double, or long double?
- by templatetypedef
According to the C++ ISO spec, §26.2/2:
The effect of instantiating the template complex for any type other than float, double or long double is unspecified.
Why would the standard authors explicitly add this restriction? This makes it unspecified, for example, what happens if you make complex<int> or a complex<MyCustomFixedPointType> and seems like an artificial restriction.
Is there a reason for this limitation? Is there a workaround if you want to instantiate complex with your own custom type?
I'm primarily asking this question because of this earlier question, in which the OP was confused as to why abs was giving bizarre outputs for complex<int>. That said, this still doesn't quite make sense given that we also might want to make complex numbers out of fixed-points types, higher-precision real numbers, etc.
Thanks!