gmpxx.h: __gmp_set_expr(mpf_ptr f, const mpz_class &z) why template?

Décio Luiz Gazzoni Filho decio at decpp.net
Tue Feb 28 15:13:20 CET 2006


On Feb 28, 2006, at 9:59 AM, Antal K wrote:

> when compiled to assembly:
> g++ -S -O3 -I.. test_0001.cc
>
>  grep call test_0001.s
>         call    __gmpf_get_default_prec
>         call    __gmpf_init2
>         call    __gmpz_init_set
>         call    __gmpf_set_z
>         call    __gmpz_clear
>         call    __gmpz_clear
>         call    _Unwind_Resume
> seems to create a temporary mpz_t.
>
> When the 'template <class T>' line is removed:
>
> grep call test_0001.s
>         call    __gmpf_get_default_prec
>         call    __gmpf_init2
>         call    __gmpf_set_z
>
> the temporary is not created.

Are you sure the same function is called? Merely removing the  
template keyword, especially considering that it seems to be  
unnecessary in this case, shouldn't result in generation of different  
code. My suspicion is that overloading rules would dictate that a  
different function would be called.

Décio



More information about the gmp-discuss mailing list