Boost logo

Ublas :

From: Neal Becker (ndbecker2_at_[hidden])
Date: 2007-08-23 14:35:28


This patch does 2 things:
1) enable mixed int/complex arith
2) use boost typeof for return type deduction

diff -r 1be5d7eb10aa boost/numeric/ublas/traits.hpp
--- a/boost/numeric/ublas/traits.hpp Mon Aug 20 09:58:57 2007 -0400
+++ b/boost/numeric/ublas/traits.hpp Thu Aug 23 14:34:22 2007 -0400
@@ -27,8 +27,44 @@
 
 #include <boost/type_traits.hpp>
 #include <complex>
+#include <boost/typeof/typeof.hpp>
 
 namespace boost { namespace numeric { namespace ublas {
+
+typedef std::complex<double> complex_t;
+
+inline complex_t operator+ (int in1, complex_t in2) {
+ return double(in1) + in2;
+}
+
+inline complex_t operator+ (complex_t in1, int in2) {
+ return in1 + double(in2);
+}
+
+inline complex_t operator- (int in1, complex_t in2) {
+ return double(in1) - in2;
+}
+
+inline complex_t operator- (complex_t in1, int in2) {
+ return in1 - double(in2);
+}
+
+inline complex_t operator* (int in1, complex_t in2) {
+ return double(in1) * in2;
+}
+
+inline complex_t operator* (complex_t in1, int in2) {
+ return in1 * double(in2);
+}
+
+inline complex_t operator/ (int in1, complex_t in2) {
+ return double(in1) / in2;
+}
+
+inline complex_t operator/ (complex_t in1, int in2) {
+ return in1 / double(in2);
+}
+
 
     // Use Joel de Guzman's return type deduction
     // uBLAS assumes a common return type for all binary arithmetic operators
@@ -37,17 +73,19 @@ namespace boost { namespace numeric { na
         typedef type_deduction_detail::base_result_of<X, Y> base_type;
         static typename base_type::x_type x;
         static typename base_type::y_type y;
- static const std::size_t size = sizeof (
- type_deduction_detail::test<
- typename base_type::x_type
- , typename base_type::y_type
- >(x + y) // Use x+y to stand of all the arithmetic actions
- );
-
- static const std::size_t index = (size / sizeof (char)) - 1;
- typedef typename mpl::at_c<
- typename base_type::types, index>::type id;
- typedef typename id::type promote_type;
+// static const std::size_t size = sizeof (
+// type_deduction_detail::test<
+// typename base_type::x_type
+// , typename base_type::y_type
+// >(x + y) // Use x+y to stand of all the arithmetic actions
+// );
+
+// static const std::size_t index = (size / sizeof (char)) - 1;
+// typedef typename mpl::at_c<
+// typename base_type::types, index>::type id;
+ // typedef typename id::type promote_type;
+ // typedef typeof (X() + Y()) promote_type;
+ typedef BOOST_TYPEOF (X() + Y()) promote_type;
     };