Skip to content

Instantly share code, notes, and snippets.

@hisui
Created December 9, 2012 08:34
Show Gist options
  • Save hisui/4243890 to your computer and use it in GitHub Desktop.
Save hisui/4243890 to your computer and use it in GitHub Desktop.
( ..)φメモメモ
// こんな感じのがあった時の話..
extern void call_later(void(*fun)(void*), void *arg);
#include <stdio.h>
#include <tuple>
template<typename Fun> void run(void *arg)
{
(*(Fun*) arg)();
}
template<typename Fun, typename ...Args>
std::pair<void(*)(void*), void*> wrap(const Fun &fun, const Args &...args)
{
auto f = [=] () { fun(args...); };
return std::make_pair
( &run<decltype(f)>
, new decltype(f)(f)); // ISSUE: dtor
}
int main()
{
void (*fun)(void*);
void *arg;
std::tie(fun, arg) = wrap(
[] (const char *msg) { puts(msg); }, "nuko");
call_later(fun, arg);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment