I have asked a similar question before overloading operator >> for lambdas
But i did not explained what i really wanted .
I am writing a simple wrapper around
What you need is a retrospective cast. A way to compose a correct function object type from passing it only a lambda (and nothing else, no template arguments, not return type specification).
A way to do it without dependencies from other libraries would be the following
#include
#include
#include
using namespace std;
template
struct memfun_type
{
using type = void;
};
template
struct memfun_type
{
using type = std::function;
};
template
typename memfun_type::type
FFL(F const &func)
{ // Function from lambda !
return func;
}
Then you can be aware of your lambas' return type and write the following
int main()
{
database_bind dbb;
dbb >> FFL([](int i, string s) { cout << i << ' ' << s << endl; });
dbb >> FFL([](int i) { cout << i << endl; });
dbb >> FFL([](string s,double d) { cout << s << ' ' << d << endl; });
}