Created
October 7, 2015 15:19
-
-
Save Gitmoko/f90355ed2f8c80df3b3e to your computer and use it in GitHub Desktop.
make std::function from lambda without describing explicit function type
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<functional> | |
namespace make_function{ | |
template<class R = void,class C = void,class... A> | |
struct impl; | |
template<class R,class C,class... A> | |
struct impl<R (C::*)(A...)const>{ | |
using type = R(*)(A...); | |
}; | |
template<class T> | |
auto make_f(T arg){ | |
using type = decltype(&T::operator()); | |
return typename impl<type>::type{arg}; | |
} | |
} | |
int main(){ | |
auto tmp = make_function::make_f([](int,char)->int{return 0;}); | |
tmp(1,'a'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment