|
Boost : |
From: Thomas Holenstein (tholenst_at_[hidden])
Date: 2000-09-06 10:02:29
Mark Rodgers writes:
> 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;
> }
> };
Yes, that would be nice. I don't like that I need to say the Result
explicit. That is, I would like the following code to compile:
---------------------------------
#include <bunch_of_things>
struct one {};
struct two {};
struct three {};
three operator+(const one& x, const two& y)
{
three z; return z;
}
int main()
{
one a;
two b;
three c = my_plus<one, two>()(a,b);
}
---------------------------------------------------------
The result is completely deducable by the compiler, at least
in theory. Its just the return type of operator+(Arg1, Arg2).
(Am I wrong here? -- i.e. can you have two different operator+?).
However, I don't see how to implement this. :-(
Thomas
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk