Why does C++ mandate that complex only be instantiated for float, double, or long double?
        Posted  
        
            by 
                templatetypedef
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by templatetypedef
        
        
        
        Published on 2012-06-19T20:18:30Z
        Indexed on 
            2012/06/19
            21:16 UTC
        
        
        Read the original article
        Hit count: 291
        
According to the C++ ISO spec, §26.2/2:
The effect of instantiating the template
complexfor any type other thanfloat,doubleorlong doubleis 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!
© Stack Overflow or respective owner