gmp-5.0.5 gmpxx ternary operator doesn't compile with shift operator

Marc Glisse marc.glisse at inria.fr
Sat May 12 16:33:02 CEST 2012


On Sat, 12 May 2012, Helmut Jarausch wrote:

> The following code does not compile with gcc-4.6.3
>
> #include <gmpxx.h>
>
> mpf_class power(const mpf_class& x) {
>  int pwr = 2;
>
>  return ( pwr < 0 ? (x>> -pwr) : (x << pwr) );
> }
>
>
> I get:
>
> In function 'mpf_class power(const mpf_class&)':
> gmpxx-bug.C:6:44: error: no match for ternary 'operator?:' in '(pwr <
> 0) ? operator>> [with T = __mpf_struct [1], U = __mpf_struct [1]]((* &
> x), ((long unsigned int)(- pwr))) : operator<< [with T = __mpf_struct
> [1], U = __mpf_struct [1]]((* & x), ((long unsigned int)pwr))'

http://gmplib.org/manual/C_002b_002b-Interface-Limitations.html

That's one of the drawbacks of expression-templates. Just write it some 
other way:

if (pwr < 0)
   return x >> -pwr;
else
   return x << pwr;


-- 
Marc Glisse


More information about the gmp-bugs mailing list