Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
success
#include <functional> #include <iostream> namespace detail{ template<typename Lambda, typename Func> struct lambda_wrapper; template <typename Lambda, typename C, typename R> struct lambda_wrapper<Lambda,R (C::*)(void) const>{ static R call(void){ Lambda x; return x(); } //typedef decltype(&call) function_type; this line of code works fine under g++ and clang but vc2015+ using function_type= R (*)(void); operator function_type (void) const { return &call;} }; template <typename Lambda, typename C, typename R, typename A0> struct lambda_wrapper<Lambda, R (C::*)(A0) const> { static R call(A0&& p0) { Lambda x; return x(std::forward<A0>(p0)); } //typedef decltype(&call) function_type; this line of code works fine under g++ and clang but vc2015+ using function_type= R (*)(A0&&); operator function_type (void) const { return &call;} }; }//end of namespace detail template <typename Lambda> struct lambda_wrapper :detail::lambda_wrapper<Lambda, decltype(&Lambda::operator())>{}; template <typename Lambda> lambda_wrapper<Lambda> wrap_lambda(const Lambda&){ return lambda_wrapper<Lambda>(); } int main(void) { typedef void(*Ptr)(); auto l = [](){ std::cout << "im broked :(" << std::endl; }; //Ptr f=l; Ptr f=wrap_lambda(l); f(); typedef void(*Ptr1)(int i); auto l1 = [](int i){ std::cout << "im happy :)" << i<<std::endl; }; //Ptr1 f1=l1; Ptr1 f1=wrap_lambda(l1); f1(3); }
run
|
edit
|
history
|
help
0
Sum of numbers in a series using sum formular
Stringify enum
Generic EventProvider
VS2013 hello world includes
Strings
throwing an exception containing a unique_ptr is dangerous
du
Operators overloading
Removing __unaligned specifier partial solution
C++ string format