#include #include #include #include #include class function_wrapper { struct impl_base { virtual void call() = 0; virtual ~impl_base() {} }; std::unique_ptr impl; template struct impl_type : impl_base { F f; impl_type(F&& f_) : f(std::move(f_)) {} void call() { f(); } }; public: template function_wrapper(F&& f) : impl(new impl_type(std::move(f))) { } void call() { impl->call(); } function_wrapper(function_wrapper&& other) : impl(std::move(other.impl)) {} function_wrapper& operator=(function_wrapper&& other) { impl = std::move(other.impl); return *this; } function_wrapper(const function_wrapper&) = delete; function_wrapper(function_wrapper&) = delete; function_wrapper& operator=(const function_wrapper&) = delete; }; class thread_pool { public: std::deque work_queue; template std::future::type> submit( FunctionType f) { typedef typename std::result_of::type result_type; std::packaged_task task(std::move(f)); std::future res(task.get_future()); work_queue.push_back(std::move(task)); return res; } // rest as before };