This is the construct definition of thread:
| Default (1) |
Thread () noexcept; |
| Initialization (2) |
Template <class Fn, class ... Args>explicit Thread (fn&& Fn, Args&& .... Args); |
| copy [deleted] (3) |
Thread (const thread&) = delete; |
| Move (4) |
Thread (thread&& x) noexcept; |
You can see that the thread is not copy, and the definition of his = operator:
| Move (1) |
thread& operator= (thread&& rhs) noexcept; |
| copy [deleted] (2) |
thread& operator= (const thread&) = delete; |
Only rvalue references (http://stackoverflow.com/questions/3106110/what-are-move-semantics) are allowed, so if you want to vector<thread> you must write this:
std::vector<std::thread> threads; for (int i=1; i<=10; ++i) threads.push_back(std::thread(increase_global,1000));
//分开写: thread t()
// thread.push_back(t) 就无法编译通过,因为要用到operator= ,而 thread只允许move semnantics,就是只允许右值引用
{
-
auto && __range = range_expression
;
-
for (auto __begin =
begin_expr
,
-
-
-
__end =
end_expr
;
range_declaratio
-
__begin != __end; ++__begin) {
- n
= *__begin; //need operator= here
- Loop_statement
-
}
}
So range for is also not available for thread