On 7/25/14 6:26 AM, Gregor Cramer wrote:
And so the function call is as expected, like with other numeric types:

pow(a) // a is BigInt

But there is now a problem in this function definition, BigInt is given as
a copy, and this is a software design issue (superfluous memory allocation).
And this currently happens if the user is calling std::num::pow() with a
numeric type like BigInt (apart from other performance penalties in pow()).

That solution doesn't work for generic code, because Rust doesn't do ad-hoc templates like C++. A function that is generic over the bigint and int "pow" functions has to have one signature for "pow". Otherwise you could get errors during template instantiation time, which is something Rust strictly avoids.

That's what I've mentioned that the compiler should decide whether an
argument is given by reference or by value.

That doesn't work. It would have numerous problems with the borrow check, etc.

I try to show the problems if function specialization (overloading) is not
supported.

Sorry, but it's not convincing to me.

Patrick

_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to