Skip to content

Instantly share code, notes, and snippets.

@Gitmoko
Created October 7, 2015 15:19
Show Gist options
  • Save Gitmoko/f90355ed2f8c80df3b3e to your computer and use it in GitHub Desktop.
Save Gitmoko/f90355ed2f8c80df3b3e to your computer and use it in GitHub Desktop.
make std::function from lambda without describing explicit function type
#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