
"Neal D. Becker" <ndbecker2@verizon.net> writes:
I believe some parts of pqs may be just what I need for some other
"David Abrahams" <dave@boost-consulting.com> wrote purposes.
I'm really interested in binary_operation. Code to infer return type of arithmetic operations is useful for other purposes, particularly since it appears to include std::complex.
As I've pointed out in the past, Joel de Guzman has posted what I believe to be the definitive implementation of this return type deduction facility.
Rather than being used to *infer* the type of the result of an operation binary_operation is actually used to construct the type of the result . In the pqs case all the result types fall into the "black hole" category in type-deduction.hpp. One use of binary_operation is to construct the return type of operator#(a,b). ie we cant do this in UDT: typeofwidget( Ta ()+ Tb () ) operator + (Ta a, Tb b); else we get the egg and chicken situation: The result type must be previously available by another mechanism I think for UDT The major work in pqs is the operator definitions. In pqs each physical quantity is composed of three parts. value_type (ie int double etc), abstract phsyical quantity (ie length time etc) and units(eg. mm, J etc). binary_operation for a physical quantity is constructed from binary_operations on these parts in a modular fashion. I have found the paramaterisation of the operation istelf useful in reducing the number of specialisations required. As I understood it result_of was once upon a time to be the official result_type candidate(N1454), which by default looks for a result_type member in its argument. With that in mind binary_operation<A,Op,B> has( should have) a single result_type member, hence: result_of<binary_operation<A,Op,B> >::type works out of the box. of course ideally one would do: result_of<A,Op,B>::type ... but that is another story However if type-deduction.hpp is now to become the official method then there is no problem (but much more work) to make it compatible: template<...> struct result_of_plus<MyTypeFirst<...>,MyTypeSecond<...> >{ typedef typename binary_operation< MyTypeFirst<..>, std::plus, // used as a token MyTypeSecond<..> >::result_type type; }; IOW type-deduction.hpp (and result_of) is a higher level construct than binary_operation. They dont do the same thing. regards Andy Little