Function return values in GMP? (James Wheaton)

Décio Luiz Gazzoni Filho decio at
Thu Mar 2 17:08:25 CET 2006

On Mar 2, 2006, at 10:21 AM, Hans Aberg wrote:

> On 2 Mar 2006, at 00:33, Décio Luiz Gazzoni Filho wrote:
>> Actually that is a well known problem with operator overloading in C+
>> + and which has been solved (though not 100% satisfactorily) using
>> the technique of `expression templates', which by the way is
>> implemented in the C++ wrapper for GMP.
> This does not solve the problem, because templates just provides a  
> static (compile time only) programming

Expression templates solve the problem for 99.9% of users. Now  
certainly there are the hardcore abstract OO types who want to do  
everything dynamically. Still, I don't see why it'd be impossible to  
use expression templates and dynamic typing simultaneously. Meaning  
you could write code like this:

base_t* x = new derived_t;
base_t* y = new derived_t;

*x = *x + *y;

and get the correct behavior without temporary generation. Of course,  
it'd require some modifications from, say, the C++ GMP wrapper in  
order to generalize it, but it's possible. Now writing code where the  
expressions themselves are generated at runtime, say a calculator  
parsing user input, might indeed not work -- I haven't thought enough  
about it to be sure.


More information about the gmp-discuss mailing list