mpq_class operator>> suggestion

Kevin Spiteri kspiteri at ieee.org
Wed Mar 15 12:08:32 CET 2006


Reference: http://swox.com/gmp/manual/C---Interface-Limitations.html

I think the default for mpq_class operator>> should behave in such a
way that a user can use it without worrying about canonicalization.
The following should work:
mpq_class a, b, c;
cin >> a >> b;
c = a / b;

Inputting without canonicalization should still be available for
efficiency. However, a user who would not want canonicalization would
know what he is doing. So I suggest having a function which could be
called as follows:
mpq_class a;
getmpq(cin, a);
This would be similar to the following code, which should work in standard C++:
string s;
getline(cin, s);

Thus, generic code would work correctly, but a user who wants to avoid
canonicalization can do so.

Best regards
Kevin


More information about the gmp-bugs mailing list