generalized arithmetic functors

STL defines some common arithmetic operators, such as template<typename T> struct plus { T operator+(const T&, constT&); }; There is a need for more general operators: template<typename T1, typename T2, typename res> struct plus { res operator+(const T1&, constT2&); }; For example, std::complex<double> + double -> std::complex<double>. Has there been any discussion on this issue?

"Neal D. Becker" <ndbecker2@verizon.net> wrote in message news:cfid8q$ukb$1@sea.gmane.org...
Has there been any discussion on this issue?
I am interested in this area: http://tinyurl.com/5qrgu also: http://www.servocomm.freeserve.co.uk/Cpp/physical_quantity/binary_operation.... OTOH look for Arkadiy Vertleybs typeof.zip in the files section. regards Andy Little

Andy Little wrote:
"Neal D. Becker" <ndbecker2@verizon.net> wrote in message news:cfid8q$ukb$1@sea.gmane.org...
Has there been any discussion on this issue?
I am interested in this area: http://tinyurl.com/5qrgu
also:
http://www.servocomm.freeserve.co.uk/Cpp/physical_quantity/binary_operation....
OTOH look for Arkadiy Vertleybs typeof.zip in the files section.
Thanks for the links. I am currently using ublas for this. It has promote_traits in traits.hpp. This does what I need, and is part of the current boost release.

"Neal D. Becker" wrote
Thanks for the links. I am currently using ublas for this. It has promote_traits in traits.hpp. This does what I need, and is part of the current boost release.
Sure... I am using Alex Gurtovoys, promotion_traits.hpp so I'll certainly take a look. One observation... As I have been moving along with my physical quantities library, I have been discovered that 'generic' result_types need this : template<...> binary_operation<LHS,plus,RHS>::result_type operator + (LHS lhs, RHS rhs); rather than template<...> promote_traits <LHS,RHS>::result_type operator+(LHS,RHS); Rationale ...for more complicated types results of (say) multiplication arent the same as for (say) addition. And for UDTs the value_types too may be compatible but different, so they need nested result_types. Another useful extension is to use enable_if, for selective overloading of operator functions. I have wrapped this up in a modified binary_operation ie binary_operation_if<Predicate,LHS,plus,RHS>::result_type operator + (LHS lhs, RHS rhs); This works well when multiplying UDTs by numerics ie int double etc, where The predicate can be "is_this_value_type a compatible value_type for my UDT". This can save a large amount of work overloading operator functions. regards Andy Little
participants (2)
-
Andy Little
-
Neal D. Becker