summaryrefslogtreecommitdiff
path: root/gmpxx.h
diff options
context:
space:
mode:
authorMarc Glisse <marc.glisse@inria.fr>2012-02-18 13:22:19 +0100
committerMarc Glisse <marc.glisse@inria.fr>2012-02-18 13:22:19 +0100
commit0a930a699bb4418754338f2eb07bda931f3a42fa (patch)
tree40e8316c9d189aa5d668edb8999d4c420d9cac9d /gmpxx.h
parent13bdb26019f57b8f16808815a347a57ca4e81299 (diff)
downloadgmp-0a930a699bb4418754338f2eb07bda931f3a42fa.tar.gz
Specialize std::common_type in C++11.
Diffstat (limited to 'gmpxx.h')
-rw-r--r--gmpxx.h26
1 files changed, 24 insertions, 2 deletions
diff --git a/gmpxx.h b/gmpxx.h
index 31c6f1da9..547960d21 100644
--- a/gmpxx.h
+++ b/gmpxx.h
@@ -42,13 +42,18 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
#if (__cplusplus >= 201103L) \
|| (__GMP_GNUC_PREREQ(4, 6) && defined __GXX_EXPERIMENTAL_CXX0X__)
#define __GMPXX_USE_CXX11 1
-#define __GMPXX_NOEXCEPT noexcept
#else
#define __GMPXX_USE_CXX11 0
-#define __GMPXX_NOEXCEPT
#endif
#endif
+#if __GMPXX_USE_CXX11
+#define __GMPXX_NOEXCEPT noexcept
+#include <type_traits> // for common_type
+#else
+#define __GMPXX_NOEXCEPT
+#endif
+
// Max allocations for plain types when converted to mpz_t
#define __GMPZ_DBL_LIMBS (2 + DBL_MAX_EXP / GMP_NUMB_BITS)
@@ -1339,7 +1344,24 @@ struct __gmp_resolve_expr<mpf_t, mpq_t>
typedef mpf_t value_type;
};
+#if __GMPXX_USE_CXX11
+namespace std {
+ template <class T, class U, class V, class W>
+ struct common_type <__gmp_expr<T, U>, __gmp_expr<V, W> >
+ {
+ private:
+ typedef typename __gmp_resolve_expr<T, V>::value_type X;
+ public:
+ typedef __gmp_expr<X, X> type;
+ };
+ template <class T, class U>
+ struct common_type <__gmp_expr<T, U>, __gmp_expr<T, U> >
+ {
+ typedef __gmp_expr<T, U> type;
+ };
+}
+#endif
// classes for evaluating unary and binary expressions
template <class T, class Op>