Hello,
I have a problem. I would like to use standart C++ <functional> function wrappers, but have a
problem. At least in MS VC 7.0 a binary_function derivate (like plus) is defined:
template<class Type>
struct plus : public binary_function
{
Type operator()(
const Type& _Left,
const Type& _Right
) const;
};
So if I am goint to add int and double value I will get int back. How can find a work around?
First I was thinking about smth like:
template
struct _ResultType
{
//some general implementation like
typedef typename _Arg1 result_type;
};
//specializations like:
template<>
struct _ResultType
{
typedef double result_type;
};
template
struct Expression
{
typedef typename _ResultType::result_type result_t;
typedef typename _BinaryFct binary_fct;
//other definitions etc...
};
somewhere in the code:
#include <functional>
Expression > myExpr;
A C++ compiler awaits a real type which causes an error. How else can I change the type of
plus<long> to plus<double>.
Probably I could write smth like this:
typedef std::plus<_ResultType > myBinaryFunction;
Expression<myBinaryFunction> myExpr;
But somehow I don't like it, since the _ResultType class will contain more information as simple
result_type. And I will need to pass it twice like:
typedef std::plus<_ResultType > myBinaryFunction;
Expression > myExpr;
This make the code not very readable...
Is there any way using boost to overcome this?
With Kind Regards,
Ovanes Markarian