Created
December 9, 2012 08:34
-
-
Save hisui/4243890 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
// こんな感じのがあった時の話.. | |
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