[Gmp-commit] /var/hg/gmp: Remove an unneeded overload of <<

mercurial at gmplib.org mercurial at gmplib.org
Sun May 15 11:36:28 CEST 2011


details:   /var/hg/gmp/rev/047945898d48
changeset: 14183:047945898d48
user:      Marc Glisse <marc.glisse at inria.fr>
date:      Sun May 15 11:36:23 2011 +0200
description:
Remove an unneeded overload of <<

diffstat:

 ChangeLog               |   5 +++++
 gmpxx.h                 |  10 +---------
 tests/cxx/t-iostream.cc |  18 ++++++++++++++++++
 3 files changed, 24 insertions(+), 9 deletions(-)

diffs (77 lines):

diff -r 5d20b365f7bc -r 047945898d48 ChangeLog
--- a/ChangeLog	Tue May 10 22:12:34 2011 +0200
+++ b/ChangeLog	Sun May 15 11:36:23 2011 +0200
@@ -1,3 +1,8 @@
+2011-05-15  Marc Glisse  <marc.glisse at inria.fr>
+
+	* gmpxx.h (operator<<): Dedup.
+	* tests/cxx/t-iostream.cc: Test on compound types.
+
 2011-05-10  Marc Glisse  <marc.glisse at inria.fr>
 
 	* gmpxx.h (__gmp_unary_expr): Let things happen in place.
diff -r 5d20b365f7bc -r 047945898d48 gmpxx.h
--- a/gmpxx.h	Tue May 10 22:12:34 2011 +0200
+++ b/gmpxx.h	Sun May 15 11:36:23 2011 +0200
@@ -1792,22 +1792,14 @@
 
 // these should (and will) be provided separately
 
-template <class T>
-inline std::ostream & operator<<
-(std::ostream &o, const __gmp_expr<T, T> &expr)
-{
-  return o << expr.__get_mp();
-}
-
 template <class T, class U>
 inline std::ostream & operator<<
 (std::ostream &o, const __gmp_expr<T, U> &expr)
 {
-  __gmp_expr<T, T> temp(expr);
+  __gmp_expr<T, T> const& temp(expr);
   return o << temp.__get_mp();
 }
 
-
 template <class T>
 inline std::istream & operator>>(std::istream &i, __gmp_expr<T, T> &expr)
 {
diff -r 5d20b365f7bc -r 047945898d48 tests/cxx/t-iostream.cc
--- a/tests/cxx/t-iostream.cc	Tue May 10 22:12:34 2011 +0200
+++ b/tests/cxx/t-iostream.cc	Sun May 15 11:36:23 2011 +0200
@@ -64,16 +64,34 @@
   }
   {
     ostringstream o;
+    mpz_class x=123;
+    o << (x+1);
+    ASSERT_ALWAYS (o.str() == "124");
+  }
+  {
+    ostringstream o;
     mpq_class x(3,4);
     o << x;
     ASSERT_ALWAYS (o.str() == "3/4");
   }
   {
     ostringstream o;
+    mpq_class x(3,4);
+    o << (x+1);
+    ASSERT_ALWAYS (o.str() == "7/4");
+  }
+  {
+    ostringstream o;
     mpf_class x=1.5;
     o << x;
     ASSERT_ALWAYS (o.str() == "1.5");
   }
+  {
+    ostringstream o;
+    mpf_class x=1.5;
+    o << (x+1);
+    ASSERT_ALWAYS (o.str() == "2.5");
+  }
 }
 
 int


More information about the gmp-commit mailing list