# HG changeset patch # User ndbecker2@gmail.com # Date 1255879287 14400 # Node ID 991ed1eb747eda2d8639e523a81a8c3b39db620e # Parent 917ad0b13fe1c35ec688bff5d815c1d906eae519 better mixed complex arith diff -r 917ad0b13fe1 -r 991ed1eb747e boost/numeric/ublas/traits.hpp --- a/boost/numeric/ublas/traits.hpp Tue Sep 29 15:01:07 2009 -0400 +++ b/boost/numeric/ublas/traits.hpp Sun Oct 18 11:21:27 2009 -0400 @@ -26,6 +26,8 @@ #include #include #include +#include +#include // anonymous namespace to avoid ADL issues namespace { @@ -43,43 +45,83 @@ namespace boost { namespace numeric { namespace ublas { - template - typename boost::enable_if, std::complex >::type inline operator+ (int in1, std::complex const& in2 ) { + template + typename boost::enable_if< + mpl::and_< + boost::is_float, + boost::is_integral + >, + std::complex >::type inline operator+ (I in1, std::complex const& in2 ) { return R (in1) + in2; } - template - typename boost::enable_if, std::complex >::type inline operator+ (std::complex const& in1, int in2) { + template + typename boost::enable_if< + mpl::and_< + boost::is_float, + boost::is_integral + >, + std::complex >::type inline operator+ (std::complex const& in1, I in2) { return in1 + R (in2); } - template - typename boost::enable_if, std::complex >::type inline operator- (int in1, std::complex const& in2) { + template + typename boost::enable_if< + mpl::and_< + boost::is_float, + boost::is_integral + >, + std::complex >::type inline operator- (I in1, std::complex const& in2) { return R (in1) - in2; } - template - typename boost::enable_if, std::complex >::type inline operator- (std::complex const& in1, int in2) { + template + typename boost::enable_if< + mpl::and_< + boost::is_float, + boost::is_integral + >, + std::complex >::type inline operator- (std::complex const& in1, I in2) { return in1 - R (in2); } - template - typename boost::enable_if, std::complex >::type inline operator* (int in1, std::complex const& in2) { + template + typename boost::enable_if< + mpl::and_< + boost::is_float, + boost::is_integral + >, + std::complex >::type inline operator* (I in1, std::complex const& in2) { return R (in1) * in2; } - template - typename boost::enable_if, std::complex >::type inline operator* (std::complex const& in1, int in2) { + template + typename boost::enable_if< + mpl::and_< + boost::is_float, + boost::is_integral + >, + std::complex >::type inline operator* (std::complex const& in1, I in2) { return in1 * R(in2); } - template - typename boost::enable_if, std::complex >::type inline operator/ (int in1, std::complex const& in2) { + template + typename boost::enable_if< + mpl::and_< + boost::is_float, + boost::is_integral + >, + std::complex >::type inline operator/ (I in1, std::complex const& in2) { return R(in1) / in2; } - template - typename boost::enable_if, std::complex >::type inline operator/ (std::complex const& in1, int in2) { + template + typename boost::enable_if< + mpl::and_< + boost::is_float, + boost::is_integral + >, + std::complex >::type inline operator/ (std::complex const& in1, I in2) { return in1 / R (in2); } diff -r 917ad0b13fe1 -r 991ed1eb747e libs/numeric/ublas/test/test11.cpp --- a/libs/numeric/ublas/test/test11.cpp Tue Sep 29 15:01:07 2009 -0400 +++ b/libs/numeric/ublas/test/test11.cpp Sun Oct 18 11:21:27 2009 -0400 @@ -92,7 +92,10 @@ v2 = v1 * value_type (1.); std::cout << "v1 * 1. = " << v2 << std::endl; v2 = v1 * t; - std::cout << "v1 * N = " << v2 << std::endl; + std::cout << "v1 * value_type(N) = " << v2 << std::endl; + // test interop with integer + v2 = v1 * N; + std::cout << "v1 * N = " << v2 << std::endl; // Some assignments initialize_vector (v1); @@ -108,6 +111,9 @@ v1 *= value_type (1.); std::cout << "v1 *= 1. = " << v1 << std::endl; v1 *= t; + std::cout << "v1 *= value_type(N) = " << v1 << std::endl; + // test interop with integer + v1 *= N; std::cout << "v1 *= N = " << v1 << std::endl; // Unary vector operations resulting in a scalar