class ThreadPool {
public:
ThreadPool(size_t);
template<class F, class... Args>
auto enqueue(F&& f, Args&&... args)
-> std::future<typename std::result_of<F(Args...)>::type>;
~ThreadPool();
private:
// need to keep track of threads so we can join them
std::vector< std::thread > workers;
// the task queue
std::queue< std::function<void()> > tasks;
// synchronization
std::mutex queue_mutex;
std::condition_variable condition;
bool stop;
};
uj5u.com熱心網友回復:
&& 這個是右值參考.... 這個代表是變長模板引數。
->這個函式回傳值推導。
=======================
一兩句話,說不大清楚,建議看看c++11方面的書
uj5u.com熱心網友回復:
右值參考和Lambda運算式uj5u.com熱心網友回復:
右值參考和Lambda運算式uj5u.com熱心網友回復:
[&total](int x){
total += x;
});
這種方式是lambda運算式
uj5u.com熱心網友回復:
auto enqueue(F&& f, Args&&... args)
-> std::future<typename std::result_of<F(Args...)>::type>;//這個函式回傳值推導中typename是什么作用?
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/166934.html
標籤:C++ 語言
