Boost logo

Boost :

From: Andy Little (andy_at_[hidden])
Date: 2004-03-23 04:31:46

"David Abrahams" <dave_at_[hidden]> wrote
> "Neal D. Becker" <ndbecker2_at_[hidden]> writes:
> > 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, particularly since
> > 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,

result_of<binary_operation<A,Op,B> >::type works out of the box.

of course ideally one would do:


... 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:

    struct result_of_plus<MyTypeFirst<...>,MyTypeSecond<...> >{
        typedef typename binary_operation<
                    std::plus, // used as a token
>::result_type type;

IOW type-deduction.hpp (and result_of) is a higher level construct than
binary_operation. They dont do the same thing.

Andy Little

Boost list run by bdawes at, gregod at, cpdaniel at, john at