Boost logo

Boost :

From: Daryle Walker (darylew_at_[hidden])
Date: 2000-09-08 00:04:35


on 9/6/00 8:30 PM, Mark Rodgers at mark.rodgers_at_[hidden] wrote:

> I was thinking of adding something like
>
> template <class Arg1, class Arg2 = Arg1, class Result = Arg1>
> struct plus : std::binary_function<Arg1,Arg2,Result>
> {
> Result operator()(typename call_traits<Arg1>::param_type x,
> typename call_traits<Arg2>::param_type y) const
> {
> return x + y;
> }
> };
>
> template <class Arg1, class Arg2 = Arg1, class Result = Arg1>
> struct minus : std::binary_function<Arg1,Arg2,Result>
> {
> Result operator()(typename call_traits<Arg1>::param_type x,
> typename call_traits<Arg2>::param_type y) const
> {
> return x - y;
> }
> };
>
> to functional.hpp. The idea would be to allow things like
>
> boost::plus<Foo*,std::ptrdiff_t,Foo*>()
> or boost::minus<Foo*,std::ptrdiff_t,Foo*>()
> or boost::minus<Foo*,Foo*,std::ptrdiff_t>()
>
> as well as the traditional
>
> boost::minus<int>()
>
> Thoughts anyone?

I like it. I like it so much that I've already put a preliminary version,
with new documentation file, in the Boost vault. They are under the
"dlw_functional" folder.

I've been wishing for classes like this for several weeks, but with another
operator (not in the standard list). I guess your post got me to start
doing it myself. I think for the next version I'll add the other extensible
operators (like << delete , [] =), then most of the remaining operators.

-- 

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