[Gmp-commit] /var/hg/gmp: Specialize std::common_type for expressions with bu...

mercurial at gmplib.org mercurial at gmplib.org
Sat Jul 28 21:46:45 CEST 2012


details:   /var/hg/gmp/rev/46d8ba67667d
changeset: 15074:46d8ba67667d
user:      Marc Glisse <marc.glisse at inria.fr>
date:      Sat Jul 28 21:46:42 2012 +0200
description:
Specialize std::common_type for expressions with builtin types.

diffstat:

 ChangeLog            |   6 ++++++
 gmpxx.h              |  25 +++++++++++++++++++++++++
 tests/cxx/t-cxx11.cc |   3 +--
 3 files changed, 32 insertions(+), 2 deletions(-)

diffs (64 lines):

diff -r a6e58bd233d3 -r 46d8ba67667d ChangeLog
--- a/ChangeLog	Sat Jul 21 19:20:43 2012 +0200
+++ b/ChangeLog	Sat Jul 28 21:46:42 2012 +0200
@@ -1,3 +1,9 @@
+2012-02-18  Marc Glisse  <marc.glisse at inria.fr>
+
+	* gmpxx.h (std::common_type): New partial specializations with builtin
+	types.
+	* tests/cxx/t-cxx11.cc: Test it.
+
 2012-07-21  Torbjorn Granlund  <tege at gmplib.org>
 
 	* mpn/powerpc32/vmx/mod_34lsub1.asm: Fix r0 clobbering issue with
diff -r a6e58bd233d3 -r 46d8ba67667d gmpxx.h
--- a/gmpxx.h	Sat Jul 21 19:20:43 2012 +0200
+++ b/gmpxx.h	Sat Jul 28 21:46:42 2012 +0200
@@ -1365,6 +1365,31 @@
   {
     typedef __gmp_expr<T, U> type;
   };
+
+#define __GMPXX_DECLARE_COMMON_TYPE(typ)	\
+  template <class T, class U>			\
+  struct common_type <__gmp_expr<T, U>, typ >	\
+  {						\
+    typedef __gmp_expr<T, T> type;		\
+  };						\
+						\
+  template <class T, class U>			\
+  struct common_type <typ, __gmp_expr<T, U> >	\
+  {						\
+    typedef __gmp_expr<T, T> type;		\
+  }
+
+  __GMPXX_DECLARE_COMMON_TYPE(signed char);
+  __GMPXX_DECLARE_COMMON_TYPE(unsigned char);
+  __GMPXX_DECLARE_COMMON_TYPE(signed int);
+  __GMPXX_DECLARE_COMMON_TYPE(unsigned int);
+  __GMPXX_DECLARE_COMMON_TYPE(signed short int);
+  __GMPXX_DECLARE_COMMON_TYPE(unsigned short int);
+  __GMPXX_DECLARE_COMMON_TYPE(signed long int);
+  __GMPXX_DECLARE_COMMON_TYPE(unsigned long int);
+  __GMPXX_DECLARE_COMMON_TYPE(float);
+  __GMPXX_DECLARE_COMMON_TYPE(double);
+#undef __GMPXX_DECLARE_COMMON_TYPE
 }
 #endif
 
diff -r a6e58bd233d3 -r 46d8ba67667d tests/cxx/t-cxx11.cc
--- a/tests/cxx/t-cxx11.cc	Sat Jul 21 19:20:43 2012 +0200
+++ b/tests/cxx/t-cxx11.cc	Sat Jul 28 21:46:42 2012 +0200
@@ -106,11 +106,10 @@
   CHECK_COMMON_TYPE (decltype(-q), decltype(-q), decltype(-q));
   CHECK_COMMON_TYPE (decltype(-f), decltype(-f), decltype(-f));
 
-  /* Not yet supported
+  /* Painful */
   CHECK_COMMON_TYPE_BUILTIN (decltype(-z), mpz_class);
   CHECK_COMMON_TYPE_BUILTIN (decltype(-q), mpq_class);
   CHECK_COMMON_TYPE_BUILTIN (decltype(-f), mpf_class);
-  */
 }
 
 template<class T, class U = T>


More information about the gmp-commit mailing list