I just play with std::function<>and operators so that C ++ expressions look like functional languages ( F#) and find out that there is a difference between operator()and operator<<. My code is:
Function 1 (Operator Overload):
function<int(int)> operator>>(function<int(int)> f1, function<int(int)> f2)
{
function<int(int)> f3 = [=](int x){return f1(f2(x));};
return f3;
}
Function 2 (operator overload):
function<int(int, int)> operator>>(function<int(int, int)> f1, function<int(int)> f2)
{
function<int(int, int)> f3 = [=](int x,int y){return f2(f1(x, y));};
return f3;
}
Function 3 (Operator Overload):
function<int(int)> operator()(function<int(int, int)> f1, int x)
{
function<int(int)> f2 = [=](int y){return f1(x, y);};
return f2;
}
while function 1 and function 2 (or operator overload), function 3 throws an error:
error: ‘std::function<int(int)> operator()(std::function<int(int, int)>, int)’ must be a nonstatic member function
function<int(int)> operator()(function<int(int, int)> f1, int x)
^
Why operator()should be a non-stationary member? I think it is different from What is the difference between the dot (.) And → operator in C ++? In this question, the answer is explained in terms of pointers. But here I am using simple operator()and operator>>that have nothing to do with pointers.