Created
June 4, 2013 19:54
-
-
Save Justasic/5709013 to your computer and use it in GitHub Desktop.
Revisions
-
Justin Crawford created this gist
Jun 4, 2013 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,41 @@ #include <iostream> #include <functional> #include <queue> // These includes are for later experimentation #include <thread> #include <atomic> std::queue<std::function<void()>> funcs; template<typename _Callable, typename... _Args> void QueueFunction(_Callable&& __f, _Args&&... __args) { std::function<void()> func = std::bind(std::forward<_Callable>(__f), std::forward<_Args>(__args)...); funcs.push(func); } void CallFuncs() { while(!funcs.empty()) { std::function<void()> func = funcs.front(); funcs.pop(); func(); } } void print_things(const std::string str) { std::cout << str << std::endl; } int main() { std::string str("Hello"); QueueFunction(print_things, str); CallFuncs(); return 0; }