Skip to content

Instantly share code, notes, and snippets.

@wengxt
Forked from yume-chan/test.cpp
Last active March 7, 2018 17:48
Show Gist options
  • Save wengxt/3a0869e7693593fb1b37063fbf6f11d0 to your computer and use it in GitHub Desktop.
Save wengxt/3a0869e7693593fb1b37063fbf6f11d0 to your computer and use it in GitHub Desktop.
#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