Boost logo

Boost :

From: Matthias Troyer (troyer_at_[hidden])
Date: 2003-05-01 04:01:05


Dear Boosters,

Section 20.3.2 of the standard defines some arithmetic function objects
like

template <class T> struct multiplies : binary_function<T,T,T> {
   T operator()(const T& x, const T& y) const { return x*y;}
};

We have several applications where we find it too restrictive that both
arguments as well as the result tyoe have to be of the same type. I
thus want to propose extended versions for Boost, like:

template <class Arg1, class Arg2=Arg1, class Res=Arg1> struct
multiplies : binary_function<Arg1,Arg2,Res> {
   Res operator()(const Arg1& x, const Arg2& y) const { return x*y;}
};

Consider e.g. the case where I want to multiply a vector of valarrays
with a factor:

std::vector<std::valarray<double> > arrays;
std::vector<std::valarray<double> > out;
std::vector<double> factors;

std::transform(arrays.begin(),arrays.end(),factors.begin(),out.begin(),
                 
multiplies<std::valarray<double>,double,std::valarray<double> >());

I could not do that with the std::multiplies function object, where all
three types have to be the same. We have written such extended versions
for all the function objects in Sec. 20.3.2 and Sec. 20.3.4 of the
standard (I don't have any such need for the comparators in Sec.
20.3.3), as well as the additional bit operation objects:

bit_and
bit_or
bit_xor
bit_not

I would like to propose to add those function objects to the
functional.hpp header of Boost, since this header already contains
other improvements to Sec. 20.3 of the standard. If Mark Rodgers and
the Boosters agree with this proposal then I would prepare some
documentation and submit the necessary patches.

Matthias


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk