I thought overloading on return type *wasn't allowed.. but apparently something changes when templates are involved.
Consider the following code:
Code:
#include <termios.h>
#include <unistd.h>
#include <functional>
#include <string>
#include <utility>
#include <iostream>
class NonCanInput
{
public:
template <typename F>
typename std::result_of<F()>::type
operator()(F arbitrary)
{
TurnOn t;
return arbitrary();
}
int operator()(std::function<int(void)> arbitrary= [](){return std::cin.get();} )
{
TurnOn t;
return arbitrary();
}
//overload >> if required
private:
class TurnOn
{
public:
TurnOn()
{
tcgetattr( STDIN_FILENO, &oldt );
newt = oldt;
newt.c_lflag &= ~( ICANON | ECHO );
tcsetattr( STDIN_FILENO, TCSANOW, &newt );
}
~TurnOn()
{
tcsetattr( STDIN_FILENO, TCSANOW, &oldt );
}
private:
struct termios oldt, newt;
};
};
The above code works fine.
I thought a template<> would be needed at the bolded part, but that shows an error called "explicit specialization in non-namespace scope".
Removing the 'template <>' works fine....and I am not not sure why (as I intended that to be a specialzation of the above) .
Any explanation?