Boost logo

Boost Users :

Subject: [Boost-users] [function] generalization of std::plus and std::multiplies with more than one argument type
From: alfC (alfredo.correa_at_[hidden])
Date: 2009-10-03 07:03:26


Does Boost have a generalization of std::plus and std::multiplies
(std_function.hpp)?

The standard defines this with only one template parameter
template <class _Tp>
struct multiplies : public binary_function<_Tp, _Tp, _Tp>
{
       _Tp
      operator()(const _Tp& __x, const _Tp& __y) const
       { return __x * __y; }
};

but I need something more general, where the types are different
multiplies<type1, type2, type2> (assuming that the result has the type
of the rhs.

of course I could just define

template <class _Tp1, class _Tp2, class Tp3>
struct multiplies : public binary_function<_Tp1, _Tp2, _Tp3>
{
       _Tp3
      operator()(const _Tp1& __x, const _Tp2& __y) const
       { return __x * __y; }
};

but I don't want to clutter my code with these pieces of basic code,
specially if something like this is already part of other facilities
in Boost.

(Or even better, it would be nice if multiples<type3(type1, type2)>
were defined, maybe I am asking to much sugar).

I need this specific kind of multiply<3 args> in order to provide a
default multiplication in the template parameters of vector space
class, i.e. unless something is explicitly defined it tries to use *
to implement scalar (pre)multiplication. (multiply<3 args> is the only
reasonable default I can think of).

Thanks,
Alfredo


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net