-
-
Save wengxt/3a0869e7693593fb1b37063fbf6f11d0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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> | |
#include <iostream> | |
template <class F> | |
struct wrapper { | |
F f; | |
}; | |
template <class F> | |
decltype(auto) make_wrapper(F&& f) { | |
return wrapper<typename std::decay<F>::type>{std::forward<F>(f)}; | |
} | |
decltype(auto) test_lambda() { | |
auto s = std::string("hello"); | |
auto l = [s]()->void { | |
std::cout << s.c_str() << std::endl; | |
}; | |
auto c = l; | |
return c; | |
} | |
decltype(auto) test_wrapper() { | |
auto s = std::string("hello"); | |
auto c = [s]()->void { | |
std::cout << s.c_str() << std::endl; | |
}; | |
return make_wrapper(c); | |
} | |
int main() | |
{ | |
auto l = test_lambda(); | |
l(); | |
auto w = test_wrapper(); | |
w.f(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment