From: Andy Little (andy_at_[hidden])
Date: 2004-03-15 10:29:24
"Neal D. Becker" <ndbecker2_at_[hidden]> wrote in message
> I believe some parts of pqs may be just what I need for some other
> I'm really interested in binary_operation. Code to infer return type of
> arithmetic operations is useful for other purposes,
binary_operation part was originally a utility for physical_quantities but
as you say I think it has potential to be useful in other ways. I think it
ties in with the whole result_of, typeof decl_type, promotion... debate.OTOH
I think there are similar moves afoot by others in the same area.
binary_operation <A,Op,B> should by design have a single result_type member
,IOW it differs from the boost::mpl:plus etc in that there is no value
member, It is a type computation only,(the fact that some specialisations in
pqs have other members is due to my sloppy coding). This means that it can
be used symmetrically for inbuilt and UDTs. And of course it is
specifically designed to provide the result_type for operators. In use:
binary_operation <A,std:plus,B>::result_type operator +(A,a, B b);
Note the template template param looks fancy but is Just used as an operator
token. Could as easy be an enum... however the binary_functions are
available in std without adding other global bits and pieces so seem
appropriate.. though some are missing.
It is also directly compatibile with result_of, e.g as alternative to above:
result_of<binary_operation<A,std::plus,B> >::type operator +(A,a, B b);
The definition of binary_operation in "boost/pqs/meta/binary_operation.hpp"
is designed for inbuilt types. Some meta-programming is used in there to
decide the return type of the operation. So == returns bool etc. The
information on operators is in
"boost/pqs/operators/binary_operator_traits.hpp" which assigns an
expression-family (multiplicative,assignment, logical_or etc) to each
operator. The enums for expression family are defined in
boost/pqs/operators/binary_operator_parameters.hpp". based on the names in C
In the pqs implementation the type of the return type for inbuilt types for
+-,* etc is found using an arithmetic_promote<A,B>::type function, based on
Alexei Gurtovois promotion_traits.hpp header (in files section). It may
also be possible to use Joel de Guzmanns type-deduction.hpp header, but I
havent experimented with this. During my own development errors have
frequently resulted in an error message in the primary binary_operation
definition which suggests I could make much better use of this... somehow.
This is very much a first try. The implementation is very basic.
Once binary_operation<a,Op,B> is specialised for a UDT pair (and the
operator functions defined) the secondary benefit is that the functor
binary_operator<A,Op,B>()(a, b) is also defined, as well as the functor
operator_plus<A,B>()(a,b), (etc) which is a user level derived
version.(definitions in "boost/pqs/operators/binary_operators.hpp"). As yet
I havent made much use of these but because Op can be a template param , may
>particularly since it
> appears to include std::complex.
Yes..std::complex for udts is ....err..hmm Fun :-). for physical_quantities
it is even more fun. I have done a quick blast through some of the
operators. At this stage I should think my implementation is a long way from
optimal, ie there may be a more concise way to achieve it. As I hope you can
appreciate from the above, I am still very much in middle of coding complex
so still figuring out best way to do it. when I'm done I will see how/if it
can be generally applied
> There seems to be absolutely no documentation, and I am no expert.
> I hope
> you will find some time to at least put some comments in the code.
Thanks for the feedback and Apologies..I take the point and will try to add
some more useful comments in the code.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk